Search code examples
javascriptethereumsoliditytruffle

truffle - artifacts.require is not a function


I am currently learning solidity and creating my first project. I am trying to test the deployment of my contract with truffle and i keep getting the below error

TypeError: artifacts.reqiure is not a function

Syntax looks correct and there are no errors appearing. I have also gone into the truffle console and the migration seems to have deployed ok and Color.json is now in my abis folder as well.

Any help will be appreciated, all files are below.

Color.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);
};

Solution

  • You have a typo in Color.test.js

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

    should be require