Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

ReferenceError: artifacts is not defined #5427

Closed
1 task
CleoPatra2772 opened this issue Aug 11, 2022 · 2 comments
Closed
1 task

ReferenceError: artifacts is not defined #5427

CleoPatra2772 opened this issue Aug 11, 2022 · 2 comments

Comments

@CleoPatra2772
Copy link

CleoPatra2772 commented Aug 11, 2022


Issue

Trying to deploy my contracts, but gets ReferenceError: artifacts is not defined

Steps to Reproduce

Here is what it looks like :

const Tether = artifacts.require("Tether");
const RWD = artifacts.require("RWD");
const DecentralBank = artifacts.require("DecentralBank");

module.exports = async function (deployer) {
    //Deploy contracts

    await deployer.deploy(Tether);
    await deployer.deploy(RWD);
    await deployer.deploy(DecentralBank);
};

What each contract looks like --

Tether:

pragma solidity ^0.5.0;

contract Tether {
    string public  name = 'Tether';
    string public symbol = 'USDT';
    uint256 public totalSupply = 1000000000000000000000000; //1 million supply tokens
    uint8 public decimals = 18;

    event Transfer(
        address indexed _from,
        address indexed _to,
        uint _value,
    );

    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint _value,
    );

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address =>uint256)) public allowance;
    constructor() public {
        balanceOf[msg.sender] = totalSupply;
    }

    function transfer(address _to, uint256 _value) public returns (bool success){
        require(balanceOf[msg.sender] >= _value);
        balanceOf[msg.sender] = balanceOf[msg.sender] - value;
        balanceOf[_to] = balanceOf[_to] + _value;
        emit Transfer(msg.sender, _to, _value);
        return true;
    }

    function approve (address _spender, uint256 _value) public returns (bool success){
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender,_spender, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
       require(_value <= balanceOf[_from]);
       require(_value <= allowance[_from][msg.sender]);
       
        balanceOf[_to] += _value;
        balanceOf[_from] -= _value;
        allowance[msg.sender][_from] -= _value;
        emit Transfer(_from, _to, _value);
        return true;
    }
}

RWD:

pragma solidity ^0.5.0;

contract RWD {
    string public  name = 'Reward Token';
    string public symbol = 'RWD';
    uint256 public totalSupply = 1000000000000000000000000; //1 million supply tokens
    uint8 public decimals = 18;

    event Transfer(
        address indexed _from,
        address indexed _to,
        uint _value,
    );

    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint _value,
    );

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address =>uint256)) public allowance;
    constructor() public {
        balanceOf[msg.sender] = totalSupply;
    }

    function transfer(address _to, uint256 _value) public returns (bool success){
        require(balanceOf[msg.sender] >= _value);
        balanceOf[msg.sender] = balanceOf[msg.sender] - value;
        balanceOf[_to] = balanceOf[_to] + _value;
        emit Transfer(msg.sender, _to, _value);
        return true;
    }

    function approve (address _spender, uint256 _value) public returns (bool success){
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender,_spender, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
       require(_value <= balanceOf[_from]);
       require(_value <= allowance[_from][msg.sender]);
       
        balanceOf[_to] += _value;
        balanceOf[_from] -= _value;
        allowance[msg.sender][_from] -= _value;
        emit Transfer(_from, _to, _value);
        return true;
    }
}

DecentralBank:

pragma solidity ^0.5.0;

contract DecentralBank {
    string public name = 'Decentral Bank';
    address public owner;
}

This is inital_migrations

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

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

Actual Results

error : ReferenceError: artifacts is not defined
ReferenceError: artifacts is not defined
    at Object.<anonymous> (/Users/cleogao/Documents/solidity/defi-staking-app-starter/defi-staking-app-starter/migrations/1_initial_migration.js:1:20)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at /Users/cleogao/.npm/_npx/c7b5aae036bba223/node_modules/migrate/lib/load-migrations.js:44:17
    at Array.map (<anonymous>)
    at /Users/cleogao/.npm/_npx/c7b5aae036bba223/node_modules/migrate/lib/load-migrations.js:40:30

Environment

  • Operating System: Mac
  • node version (node --version): v16.16.0
  • npm version (npm --version):
  • Truffle v5.1.39 (core: 5.1.39)
    Solidity - ^0.5.0 (solc-js)
@cds-amal
Copy link
Member

Hi @CleoPatra2772, you are using an outdated Truffle version. Can you upgrade and see if it resolves your issue? To upgrade: npm -g uninstall truffle && npm -g install truffle. Thanks!

@CleoPatra2772
Copy link
Author

Hi @CleoPatra2772, you are using an outdated Truffle version. Can you upgrade and see if it resolves your issue? To upgrade: npm -g uninstall truffle && npm -g install truffle. Thanks!

Yep. It seems to be the problem. thanks !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants