Unable to run the smartContract using Truffle Console. Getting error

556 views Asked by At

I am trying to run the following smart contract:

pragma solidity ^0.5.0;

contract Calculator{
        function addition(uint a, uint b) public pure returns(uint) {
                return (a + b);
        }

        function substraction(uint a, uint b) public pure returns(uint) {
                return (a - b);
        }

        function multiplication(uint a, uint b) public pure returns(uint) {
                return ( a * b);
        }

        function division (uint a, uint b) public pure returns(uint) {
                return (a / b);
        }
}

While I try to run the smart contract using truffle console it errors out stating "insufficient funds for gas"

sudo truffle console
truffle(development)> Calculator.deployed().then(function(instance) { app = instance;})
undefined
truffle(development)> app.multiplication(5, 5, {from: web3.eth.accounts[0]});
Uncaught:
Error: Returned error: err: insufficient funds for gas * price + value (supplied gas 25000000)
    at evalmachine.<anonymous>:0:5
    at sigintHandlersWrap (vm.js:272:15)
    at Script.runInContext (vm.js:127:14)
    at runScript (/usr/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:251:1)
    at Console.interpret (/usr/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:266: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)
    at ReadStream.emit (events.js:315:20)
    at ReadStream.EventEmitter.emit (domain.js:483:12)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at ReadStream.Readable.push (_stream_readable.js:212:10)
    at TTY.onStreamRead (internal/stream_base_commons.js:186:23)
    at TTY.callbackTrampoline (internal/async_hooks.js:120:14) {
  hijackedStack: 'Error: Returned error: err: insufficient funds for gas * price + value (supplied gas 25000000)\n' +
    '    at Object.ErrorResponse (/usr/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/src/errors.js:29:1)\n' +
    '    at /usr/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-requestmanager/src/index.js:140:1\n' +
    '    at /usr/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:112:1\n' +
    '    at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/build/webpack:/node_modules/web3-providers-http/src/index.js:96:1)\n' +
    '    at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)\n' +
    '    at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)\n' +
    '    at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)\n' +
    '    at IncomingMessage.<anonymous> (/usr/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)'
}
truffle(development)>

In my truffle-config.js file:

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)
     },
     live: {
       network_id: 2020,
       host: "127.0.0.1",
       port: 8545,
       from: "0x79b10CF39809f29160197ecbBdb21635684B0E45",
       gas: 8000000000,
       gasPrice: 20000000000
     },

Any idea why? or can you get me some idea on how to get this working. i tried increasing the gas limit multiple times but nothing helped.

1

There are 1 answers

0
Vladyslav Munin On BEST ANSWER

Gas property defines how much of gas is sent with each transaction. The gas limit is very high. Total value for transaction is gas * gasPrice. So you send during the deployment / tx by default 160000000000 gwei ( 160 ether). If you use some test client as ganache, basic amount for test addresses is 100 ether per account.

I tried to deploy the contract on standard setting (gas: 6700000) and everything is fine. With your config example gas exceeded the block limit during the deployment. If you were succeeded with deployment somehow, that means that your 'live env' configuration allows such gas limit. EVM returns remaining gas of tx to you, but in your case it's too much to send it.