无法 运行 使用 Truffle 控制台的智能合约。出现错误
Unable to run the smartContract using Truffle Console. Getting error
我正在尝试运行以下智能合约:
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);
}
}
当我尝试 运行 使用 truffle 控制台的智能合约时,它错误地指出“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)>
在我的松露-config.js 文件中:
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
},
知道为什么吗?或者你能给我一些关于如何让它工作的想法吗?我多次尝试提高气体限制,但没有任何帮助。
Gas 属性 定义每笔交易发送多少 gas。气体限制非常高。交易的总价值是 gas * gasPrice。所以你在部署/tx 期间默认发送 160000000000 gwei(160 以太币)。如果你使用一些测试客户端作为 ganache,测试地址的基本数量是每个账户 100 以太币。
我尝试在标准设置(gas:6700000)上部署合约,一切正常。使用您的配置示例,gas 在部署期间超过了块限制。如果您以某种方式成功部署,则意味着您的 'live env' 配置允许这样的 gas 限制。 EVM returns 剩余的 tx gas 给你,但在你的情况下发送它太多了。
我正在尝试运行以下智能合约:
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);
}
}
当我尝试 运行 使用 truffle 控制台的智能合约时,它错误地指出“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)>
在我的松露-config.js 文件中:
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
},
知道为什么吗?或者你能给我一些关于如何让它工作的想法吗?我多次尝试提高气体限制,但没有任何帮助。
Gas 属性 定义每笔交易发送多少 gas。气体限制非常高。交易的总价值是 gas * gasPrice。所以你在部署/tx 期间默认发送 160000000000 gwei(160 以太币)。如果你使用一些测试客户端作为 ganache,测试地址的基本数量是每个账户 100 以太币。
我尝试在标准设置(gas:6700000)上部署合约,一切正常。使用您的配置示例,gas 在部署期间超过了块限制。如果您以某种方式成功部署,则意味着您的 'live env' 配置允许这样的 gas 限制。 EVM returns 剩余的 tx gas 给你,但在你的情况下发送它太多了。