Ethereum 错误:用于天然气价格的资金不足+;价值

Ethereum 错误:用于天然气价格的资金不足+;价值,ethereum,go-ethereum,remix,Ethereum,Go Ethereum,Remix,我正在通过考试 我使用Remix编译了合同代码,并创建了以下脚本。为了简洁起见,我删除了二进制字符串: var _greeting = 'Hello World!'; var browser_untitled_sol_greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable",

我正在通过考试

我使用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);
   }
})
加载此脚本时,我得到:

错误:用于天然气*价格+价值的资金不足

调用
eth.getBalance(eth.accounts[0])
时,我得到:
39957700000000

我无法计算我的余额中应该有多少乙醚才能运行此脚本,或者我是否需要将乙醚转换为气体。

您不能将乙醚“转换”为气体。你用乙醚来支付汽油的使用费

无论如何,您收到的错误消息似乎是正确的。你的余额很低
eth.getBalance()
返回单位为的余额。您的余额只有~0.0004乙醚,这相当低(您可以使用
web3.fromWei(val,'ether')
转换为乙醚或在代码中转换为乙醚)


您需要的乙醚量取决于合同中执行的操作,以及您愿意为所用气体支付的金额(您可以覆盖事务对象中的默认值
gasPrice
)。尝试挖掘或将更多以太传输到您的帐户。

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

它是1美元。创建一份合同怎么会花这么多钱?不知道你是怎么想到的。0004乙醚<0.15美元。成本将取决于您的合同代码中有多少逻辑以及您希望它被挖掘的速度。