Search code examples
ethereumsoliditysmartcontractstrufflenft

error migrating contract with inheritance using truffle


I get this error when trying to migrate a contract with an inheritance

Error: "NFTCollectible" -- Invalid number of parameters for "undefined". Got 0 expected 1!.

/contracts/NFTCollectible.sol

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";

contract NFTCollectible is ERC721Enumerable, Ownable {
        using SafeMath for uint256;
        using Counters for Counters.Counter;
        ...    
    }

/migrations/2_deploy_contracts.js

var NFTCollectible = artifacts.require("NFTCollectible");

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

Solution

  • this is the NFTCollectible contract on the page:

    enter image description here

    so this contract has a constructor method and it requires 1 argument. so when you deploy the contract, you have to pass the parameter to the conract as below:

    var NFTCollectible = artifacts.require("NFTCollectible");
    
    module.exports = function(deployer) {
        // you have to pass the baseURI
        deployer.deploy(NFTCollectible,"https://baseUriHere");
    };