Token is not deployed

I get the following error when I run “truffle migrate”

ReferenceError: Token is not defined
at module.exports (/Users/Eleanor/Desktop/Blockchain/DAPP/academy-kitties-template-master/migrations/1_initial_migration.js:4:19)
at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:55:1)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:217:1)
at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
at Object.runAll (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:114:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:79:1)
at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:76:1)
at Object.module.exports [as run] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:44:1)

This is my code in the migrations file:

const Token = artifacts.require("Santacontract");

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

This is my contract code:

pragma solidity ^0.8.0;

import "./IERC721.sol";

contract Santacontract is IERC721 {
    //Token name
    string public constant _name = "SantaFactory";
    //Token symbol
    string public constant _symbol = "SF";

    struct Santa {
        uint256 genes;
        uint64 birthTime;
        uint32 mumId;
        uint32 dadId;
        uint16 generation;
    }

    Santa[] santas;

    // constructor(
    //     uint256 memory totalSupply_,
    //     string memory name_,
    //     string memory symbol_
    // ) {
    //     _totalSupply = totalSupply_;
    //     _name = name_;
    //     _symbol = symbol_;
    // }

    // Mapping from token ID to owner address
    mapping(uint256 => address) public santaIndexToOwner;

    // Mapping owner address to token count
    mapping(address => uint256) ownershipTokenCount;

    function balanceOf(address owner) external view returns (uint256 balance) {
        return ownershipTokenCount[owner];
    }

    function totalSupply() public view returns (uint256) {
        return santas.length;
    }

    function name() external pure returns (string memory tokenName) {
        return _name;
    }

    function symbol() external pure returns (string memory tokenSymbol) {
        return _symbol;
    }

    function ownerOf(uint256 _tokenId) external view returns (address) {
        address owner = santaIndexToOwner[_tokenId];
        return owner;
    }

    function transfer(address _to, uint256 _tokenId) external {
        require(_to != address(0), "ERC721: owner query for nonexistent token");
        require(
            _to != address(this),
            "ERC721: owner query for contract address"
        );
        require(_owns(msg.sender, _tokenId));
        _transfer(msg.sender, _to, _tokenId);
    }

    function _transfer(
        address _from,
        address _to,
        uint256 _tokenId
    ) internal {
        ownershipTokenCount[_to]++;
        santaIndexToOwner[_tokenId] = _to;

        if (_from != address(0)) {
            ownershipTokenCount[_from]--;
        }

        //Emit the transfer event
        emit Transfer(_from, _to, _tokenId);
    }

    function _owns(address _claimant, uint256 _tokenId)
        internal
        view
        returns (bool)
    {
        return santaIndexToOwner[_tokenId] == _claimant;
    }
}

May I also check if we still need to install ganache as if I run truffle dev I can receive the 9 addresses and private keys already

1 Like

Hey @Eleanor_Tay, hope you are well.

when you are importing the contract on the migration file through the artifacts.require, it should match with the file name of the contract (not the contract name, file name like “santacontract.sol”, but without the format at the end).

Carlos Z

Hi @thecil, my file name is also called Santacontract.sol
I have also posted my files here if it helps:
https://github.com/nortay250/santa-factory

Thank you for providing a github repo man, its make easier for us to replicate the issue :muscle:

Now I found this on your 1_initial_migration.js
image

Just have to point the proper variable (which is Migrations for this file), after this, i was able to deploy properly the contract. (Im using truffle develop and then migrate --reset all)

Carlos Z

Thanks @thecil! Unfortunately after changing my Token to Migrations, I get this error which has to do with the IERC721.sol

1 Like

It might be an issue with NodeJs probably, take a look into this guide to downgrade the version:

Carlos Z

Hi @thecil, may I know which version of truffle and node you are using?
Currently I am using the below and I still get the error on the IERC721.sol
Truffle v5.0.1 (core: 5.0.1)
Solidity - 0.8.10 (solc-js)
Node v10.19.0

I read another article ([Truffle] migration returns "Cannot read property 'addFunction' of undefined") that I should use the latest version of truffle. However, I cannot run Truffle v5.4.28 on a node v10

1 Like

I’m using version 12 for NodeJS, which allows me to use the latest version of truffle.

Carlos Z

@thecil

Hola Carlos, hope your well, Happy new year by the way. Im having an issue deploying my ).8.0 solidity token contract in new project. Think you can take a look? thanks man.

2_deploy_token_migration.js
===========================

   Deploying 'Mosiah'
   ------------------

Error:  *** Deployment Failed ***

"Mosiah" -- Invalid number of parameters for "undefined". Got 3 expected 0!.

    at C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:365:1
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Migration._deploy (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:70:1)
    at Migration._load (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:56:1)
    at Migration.run (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:217:1)
    at Object.runMigrations (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
    at Object.runFrom (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
    at Object.runAll (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1)
    at Object.run (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:79:1)
    at runMigrations (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate\run.js:76:1)
    at Object.module.exports [as run] (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate\run.js:44:1)
    at Command.run (C:\Users\jflor\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:189:1)
- Blocks: 0            Seconds: 0
- Saving migration to chain.

truffle(develop)>
`...
 

Token contract

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.2;

import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;

import “@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol”;

import “@openzeppelin/contracts/security/Pausable.sol”;

import “@openzeppelin/contracts/access/Ownable.sol”;

import “@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol”;

import “@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol”;

import “@openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol”;

contract Mosiah is ERC20, ERC20Burnable, Pausable, Ownable, ERC20Permit, ERC20Votes, ERC20FlashMint {

constructor() ERC20("Mosiah", "MOS") ERC20Permit("Mosiah") {

    _mint(msg.sender, 333333333 * 10 ** decimals());

}

function pause() public onlyOwner {

    _pause();

}

function unpause() public onlyOwner {

    _unpause();

}

function _beforeTokenTransfer(address from, address to, uint256 amount)

    internal

    whenNotPaused

    override

{

    super._beforeTokenTransfer(from, to, amount);

}

// The following functions are overrides required by Solidity.

function _afterTokenTransfer(address from, address to, uint256 amount)

    internal

    override(ERC20, ERC20Votes)

{

    super._afterTokenTransfer(from, to, amount);

}

function _mint(address to, uint256 amount)

    internal

    override(ERC20, ERC20Votes)

{

    super._mint(to, amount);

}

function _burn(address account, uint256 amount)

    internal

    override(ERC20, ERC20Votes)

{

    super._burn(account, amount);

}

}

Truffle v5.4.27 (core: 5.4.27)
Solidity - 0.8.10 (solc-js)
Node v16.13.0
Web3.js v1.5.3

Apparently you are sending some arguments to the contract when your deploying, while this one does not need any.

Check and share your migration file for that contract, the issue might be there.

Carlos Z

It worked, thanks so much! :slight_smile:

1 Like

@thecil
Yes, it worked , thank you.

1 Like

Hi @thecil
Sorry… ran into another error when I tried to compile my contract after adding the _createSanta function in the next video, would you be able to help?

“Santacontract” is an abstract contract or an interface and cannot be deployed.

  • Import abstractions into the ‘.sol’ file that uses them instead of deploying them separately.
  • Contracts that inherit an abstraction must implement all its method signatures exactly.
  • A contract that only implements part of an inherited abstraction is also considered abstract.
at Deployer._preFlightCheck (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-deployer/src/deployment.js:178:1)

https://github.com/nortay250/santa-factory

Hey @Eleanor_Tay, hope you are ok.

Abstract contracts refers to those contract that does not need to be initialized at deployment, since your contract does not have a constructor, this warning message appear.

Are you sure the github repo is updated? I do not have that error when compiling your contracts

Using this versions:
image

Carlos Z

@thecil
Hi, Ive tested locally , now on BSC testnet and Im getting this error, Think you can take look for me?
Thanks Carlos.

typeUnhandledRejections detected
Promise {
  <rejected> {
    code: -32603,
    message: 'ETIMEDOUT',
    data: { originalError: [Object] }
  }
} {
  code: -32603,
  message: 'ETIMEDOUT',
  data: { originalError: { code: 'ETIMEDOUT', connect: true } }
}
Promise {
  <rejected> {
    code: -32603,
    message: 'ETIMEDOUT',
    data: { originalError: [Object] }
  }
} {
  code: -32603,
  message: 'ETIMEDOUT',
  data: { originalError: { code: 'ETIMEDOUT', connect: true } }
}
Promise {
  <rejected> {
    code: -32603,
    message: 'ETIMEDOUT',
    data: { originalError: [Object] }
  }
} {
  code: -32603,
  message: 'ETIMEDOUT',
  data: { originalError: { code: 'ETIMEDOUT', connect: true } }
}
Promise {
  <rejected> {
    code: -32603,
    message: 'read ECONNRESET',
    data: { originalError: [Object] }
  }
} {
  code: -32603,
  message: 'read ECONNRESET',
  data: {
    originalError: { errno: -4077, code: 'ECONNRESET', syscall: 'read' }
  }
}
 or paste code here

truffle config file

 const HDWalletProvider = require('@truffle/hdwallet-provider');
//
// const fs = require('fs');
 const mnemonic = require("./secrets.json").mnemonic;

module.exports = {
  /**
   * Networks define how you connect to your ethereum client and let you set the
   * defaults web3 uses to send transactions. If you don't specify one truffle
   * will spin up a development blockchain for you on port 9545 when you
   * run `develop` or `test`. You can ask a truffle command to use a specific
   * network from the command line, e.g
   *
   * $ truffle test --network <network-name>
   */

  networks: {
    // Useful for testing. The `development` name is special - truffle uses it by default
    // if it's defined here and no other network is specified at the command line.
    // You should run a client (like ganache-cli, geth or parity) in a separate terminal
    // tab if you use this network and you must also set the `host`, `port` and `network_id`
    // options below to some value.
    //
     development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
     },
    // Another network with more advanced options...
    // advanced: {
    // port: 8777,             // Custom port
    // network_id: 1342,       // Custom network
    // gas: 8500000,           // Gas sent with each transaction (default: ~6700000)
    // gasPrice: 20000000000,  // 20 gwei (in wei) (default: 100 gwei)
    // from: <address>,        // Account to send txs from (default: accounts[0])
    // websocket: true        // Enable EventEmitter interface for web3 (default: false)
    // },
    // Useful for deploying to a public network.
    // NB: It's important to wrap the provider as a function.
    bsctestnet: {
      provider: () => new HDWalletProvider(mnemonic,'https://speedy-nodes-nyc.moralis.io/20b22d13a459497d2f965a8c/bsc/testnet'),
      network_id: 97,
      confirmations: 10,
      timeoutBlocks: 9000,
      skipDryRun: true
    },
    // Useful for private networks
    // private: {
    // provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
    // network_id: 2111,   // This network is yours, in the cloud.
    // production: true    // Treats this network as if it was a public net. (default: false)
    // }
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.10",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    }
  },

  // Truffle DB is currently disabled by default; to enable it, change enabled:
  // false to enabled: true. The default storage location can also be
  // overridden by specifying the adapter settings, as shown in the commented code below.
  //
  // NOTE: It is not possible to migrate your contracts to truffle DB and you should
  // make a backup of your artifacts to a safe location before enabling this feature.
  //
  // After you backed up your artifacts you can utilize db by running migrate as follows: 
  // $ truffle migrate --reset --compile-all
  //
  // db: {
    // enabled: false,
    // host: "127.0.0.1",
    // adapter: {
    //   name: "sqlite",
    //   settings: {
    //     directory: ".db"
    //   }
    // }
  // }
};

Hello sir , I want to deploy my token on bsctestnet soo I do all the things but in error it is showing
Could not create address from ur private keys , please check inputs are correct
But my mnemonic is right as I check