【问题标题】:truffle - artifacts.require is not a function松露 - artifacts.require 不是函数
【发布时间】:2021-07-26 08:32:56
【问题描述】:

我目前正在学习 Solidity 并创建我的第一个项目。我正在尝试使用松露测试我的合同的部署,但我不断收到以下错误

TypeError: artifacts.reqiure is not a function

语法看起来正确并且没有出现错误。我也进入了 truffle 控制台,迁移似乎已经部署好,Color.json 现在也在我的 abis 文件夹中。

任何帮助将不胜感激,所有文件都在下面。

颜色.sol

pragma solidity 0.5.0;

import "./ERC721Full.sol";

contract Color is ERC721Full {

  // Initialise function 
  constructor () ERC721Full("Color", "COLOR") public {
    
  }

}

Color.test.js

const Color = artifacts.reqiure('./Color.sol')

require('chai')
  .use(require('chai-as-promised'))
  .should()

contract('Color', (accounts) => {
  let contract
  
  before(async () => {
    contract = await Color.deployed()
  })

  describe('deployment,', async() => {
    it('deploys successfully', async() => {
      contract = await Color.deployed()
      const address = contract.address
      console.log(address)
      assert.notEqual(address,"")
      assert.notEqual(address, 0x0)
      assert.notEqual(address, null)
      assert.notEqual(address, undefined)
    })

    it('has a name', async () => {
      const name = await contract.name()
      assert.equal(name, 'Color')
    })

    it('has a symbol', async () => {
      const symbol = await contract.symbol()
      assert.equal(symbol, 'COLOR')
    })
  })
})

2_deploy_contracts.js

const Color = artifacts.require("Color");

module.exports = function(deployer) {
  deployer.deploy(Color);
};

1_init_migration.js

const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

【问题讨论】:

    标签: javascript ethereum solidity truffle


    【解决方案1】:

    您在 Color.test.js 中有错字

    const Color = artifacts.reqiure('./Color.sol')
    

    应该是require

    【讨论】:

      【解决方案2】:

      我尝试了这个特定的代码,它显示了一条错误消息,在查看该行后,它只是颜色代码中该特定行中的一个小拼写错误:-

      const Color = artifacts.reqiure('./Color.sol')
      
      

      尝试用这个替换它:-

      const Color = artifacts.require('./Color.sol')
      

      【讨论】:

        【解决方案3】:

        确保你有

        require('@nomiclabs/hardhat-truffle5');
        

        在您尝试致电artifacts.require之前

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-07-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-02-07
          • 1970-01-01
          • 2022-01-13
          • 1970-01-01
          相关资源
          最近更新 更多