truffle - artifacts.require 不是一个函数

问题描述 投票:0回答:3

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

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 {
    
  }

}

颜色.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
3个回答
4
投票

确保你有

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

在您尝试致电之前

artifacts.require


2
投票

您在 Color.test.js 中有一个拼写错误

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

应该是

require


1
投票

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

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

尝试将其替换为:-

const Color = artifacts.require('./Color.sol')
© www.soinside.com 2019 - 2024. All rights reserved.