【问题标题】:Error: insufficient funds for gas * price + value错误:gas * price + value 资金不足
【发布时间】:2018-05-03 02:09:12
【问题描述】:

我正在通过first tutorial in the Ethereum website

我已经使用 Remix 编译了合约代码并创建了以下脚本。为简洁起见,我删除了二进制字符串:

var _greeting = 'Hello World!';
var browser_untitled_sol_greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
var browser_untitled_sol_greeter = browser_untitled_sol_greeterContract.new(
 _greeting,
 {
   from: web3.eth.accounts[0], 
   data: 'BINARY_STRING', 
   gas: '4700000'
 }, function (e, contract){
   console.log(e, contract);
   if (typeof contract.address !== 'undefined') {
     console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
   }
})

var browser_untitled_sol_mortalContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
var browser_untitled_sol_mortal = browser_untitled_sol_mortalContract.new(
   {
     from: web3.eth.accounts[0], 
     data: 'BINARY_STRING', 
     gas: '4700000'
   }, function (e, contract){
     console.log(e, contract);
     if (typeof contract.address !== 'undefined') {
       console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
   }
})

加载此脚本时,我得到:

Error: insufficient funds for gas * price + value.

当调用eth.getBalance(eth.accounts[0]) 我得到:399577000000000

我不知道我的余额中应该有多少 eth 才能运行此脚本,或者我是否需要将 eth 转换为 gas。

【问题讨论】:

    标签: ethereum go-ethereum remix


    【解决方案1】:

    您不会将以太“转换”为气体。你用以太币来支付所用的gas。

    无论如何,您收到的错误消息似乎是正确的。你的余额很低。 eth.getBalance() 返回 Wei 中的余额。你的余额只有 ~0.0004 以太币,这非常低(你可以使用 https://etherconverter.online/ 转换为以太币或使用 web3.fromWei(val, 'ether') 转换为代码)。

    你需要的以太币数量取决于合约中执行的操作,以及你愿意为所用的gas支付多少(你可以覆盖交易对象中的默认gasPrice)。尝试挖掘或将更多以太币转入您的帐户。

    【讨论】:

    • 1 美元。创建一个合同怎么会花这么多钱?
    • 不知道你是怎么想出来的。 .0004 以太币
    【解决方案2】:

    哪种网络,testrpc私有网络?如果您在以geth init genesis.json 初始化的私有网络上发送交易,请不要将chainId 设置为0

    【讨论】:

      猜你喜欢
      • 2017-08-15
      • 2018-03-20
      • 2021-11-19
      • 2019-01-03
      • 2019-04-18
      • 1970-01-01
      • 2022-06-11
      • 2021-05-13
      • 2018-04-30
      相关资源
      最近更新 更多