Truffle Console Error When Trying To Access The "totalSupply" Of Tokens In My Dapp

Viewed 279

Here's the file I have so far in my contracts directory:

pragma solidity >=0.4.22 <0.9.0;

contract Token {
    uint256 public totalSupply;

    constructor(uint _initialSupply) public {
        totalSupply = _initialSupply;
    }
}

And the text in the file I have in my migrations directory:

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

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

So I open the truffle console, and enter this:

truffle(development)> Token.deployed().then(function(instance) {token = instance;})

So far so good. Now, here's where I get the error:

truffle(development)> token.totalSupply()

Then I get this:

Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.
    at evalmachine.<anonymous>:0:3
    at sigintHandlersWrap (vm.js:272:15)
    at Script.runInContext (vm.js:127:14)
    at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:270:1)
    at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:285:1)
    at bound (domain.js:427:14)
    at REPLServer.runBound [as eval] (domain.js:440:12)
    at REPLServer.onLine (repl.js:760:10)
    at REPLServer.emit (events.js:315:20)
    at REPLServer.EventEmitter.emit (domain.js:483:12)
    at REPLServer.Interface._onLine (readline.js:329:10)
    at REPLServer.Interface._line (readline.js:658:8)
    at REPLServer.Interface._ttyWrite (readline.js:1003:14)
    at REPLServer.self._ttyWrite (repl.js:850:9)
    at ReadStream.onkeypress (readline.js:205:10)
    at ReadStream.emit (events.js:315:20)
    at ReadStream.EventEmitter.emit (domain.js:483:12)
    at emitKeys (internal/readline/utils.js:335:14)
    at emitKeys.next (<anonymous>)
    at ReadStream.onData (readline.js:1137:36) {
  hijackedStack: "Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.\n" +
    '    at ABICoder.decodeParametersWith (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/lib/index.js:298:1)\n' +
    '    at ABICoder.decodeParameters (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/lib/index.js:285:1)\n' +
    '    at Contract._decodeMethodReturn (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:470:1)\n' +
    '    at Method.outputFormatter (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:760:1)\n' +
    '    at Method.formatOutput (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-core-method/lib/index.js:147:1)\n' +
    '    at sendTxCallback (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-core-method/lib/index.js:523:1)\n' +
    '    at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-core-requestmanager/lib/index.js:308:1\n' +
    '    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:107:1\n' +
    '    at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-http/lib/index.js:98:1)\n' +
    '    at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)\n' +
    '    at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)\n' +
    '    at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)\n' +
    '    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)\n' +
    '    at IncomingMessage.emit (events.js:327:22)\n' +
    '    at IncomingMessage.EventEmitter.emit (domain.js:506:15)\n' +
    '    at endReadableNT (_stream_readable.js:1220:12)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:84:21)'
}

And now I'm confused. It's supposed to return some information referencing the amount of tokens (10000).

0 Answers
Related