Contract-Development

如何在私有區塊鏈上模擬耗盡氣體事件?

  • April 12, 2016

我想在 eth.sendTransaction 呼叫期間收到錯誤消息“Intrinsic gas too low”。

是否可以模擬私有區塊鏈場景中gas用完的情況?

有人可以指出理解這種情況和其他可能的邊緣情況的方法嗎?

編輯-

web3.fromWei(eth.getBalance(eth.accounts

$$ 0 $$), “乙太”) 21 eth.sendTransaction({來自:eth.accounts

$$ 0 $$,至:eth.accounts$$ 1 $$, gas:100000, value: web3.toWei(10, “ether”)}) miner.start (1); admin.sleepBlocks (1); miner.stop();

web3.fromWei(eth.getBalance(eth.accounts

$$ 0 $$), “乙太”) 21

為什麼我的 coinbase 賬戶餘額還是 21?

重新發送您的交易,指定更高的汽油量。

如果您gas在呼叫中省略參數,則eth.sendTransaction(...)預設值為 21000 用於普通交易。

模擬氣體耗盡:

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], gas:21000, value: web3.toWei(10, "ether")})
"0xcff42095692bb7ae72bbebbdbc7e177780e3d55859b96d7bfe561c695462d569"

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], gas:1000, value: web3.toWei(10, "ether")})
Intrinsic gas too low
   at InvalidResponse (<anonymous>:-81662:-108)
   at send (<anonymous>:-156322:-108)
   at sendTransaction (<anonymous>:-133322:-108)
   at <anonymous>:1:1

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], gas:100000, value: web3.toWei(10, "ether")})
"0x03e337d75ed319b15029bdca7c491e48acde4cfa44594f50df4cfb7aac5d7f53"

當你發送交易時,你應該得到一個交易雜湊。

你可能不得不讓你的礦工再執行幾個街區。刪除您的admin.sleepBlocks(1); miner.stop();聲明。

如果交易成功,您將得到類似以下結果 - 第一次呼叫eth.getTransaction(...)顯示該交易尚未被探勘(blockNumber 為空)。第二個呼叫顯示了探勘的交易(blockNumber 是 1476)。在此之後,您的帳戶應扣除金額。

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], gas:100000, value: web3.toWei(10, "ether")})
I0412 23:36:08.702030   21319 xeth.go:1028] Tx(0x511ac8d69452f0791b57ab62e7c5261119463696c01ed81fb1e58d637d46cab5) to: 0x043f7fdc6e789060bfad91f7bba100d20a1cdf18
"0x511ac8d69452f0791b57ab62e7c5261119463696c01ed81fb1e58d637d46cab5"
> eth.getTransaction("I0412 23:36:18.881647   21319 worker.go:348] 🔨  Mined block (#1475 / 37440f0d). Wait 5 blocks for confirmation
VM STAT 0 OPs
I0412 23:36:18.882734   21319 worker.go:569] commit new work on block 1476 with 1 txs & 0 uncles. Took 1.023896ms
VM STAT 0 OPs
I0412 23:36:18.883282   21319 worker.go:569] commit new work on block 1476 with 1 txs & 0 uncles. Took 488.218µs
0x511ac8d69452f0791b57ab62e7c5261119463696c01ed81fb1e58d637d46cab5")
{
 blockHash: null,
 blockNumber: null,
 from: "0x8d15cd39bdb00d5362775002c342c168ee707400",
 gas: 100000,
 gasPrice: 20000000000,
 hash: "0x511ac8d69452f0791b57ab62e7c5261119463696c01ed81fb1e58d637d46cab5",
 input: "0x",
 nonce: 4,
 to: "0x043f7fdc6e789060bfad91f7bba100d20a1cdf18",
 transactionIndex: null,
 value: 10000000000000000000
}
> I0412 23:36:23.527844   21319 worker.go:348] 🔨  Mined block (#1476 / ca7817a9). Wait 5 blocks for confirmation
I0412 23:36:23.528429   21319 worker.go:569] commit new work on block 1477 with 0 txs & 0 uncles. Took 505.461µs
I0412 23:36:23.528831   21319 worker.go:569] commit new work on block 1477 with 0 txs & 0 uncles. Took 312.822µs
> eth.getTransaction("0x511ac8d69452f0791b57ab62e7c5261119463696c01ed81fb1e58d637d46cab5")
{
 blockHash: "0xca7817a90043b4c069e581d3ceb9bae0d147cd26f10a439410909d06fdaac5d0",
 blockNumber: 1476,
 from: "0x8d15cd39bdb00d5362775002c342c168ee707400",
 gas: 100000,
 gasPrice: 20000000000,
 hash: "0x511ac8d69452f0791b57ab62e7c5261119463696c01ed81fb1e58d637d46cab5",
 input: "0x",
 nonce: 4,
 to: "0x043f7fdc6e789060bfad91f7bba100d20a1cdf18",
 transactionIndex: 0,
 value: 10000000000000000000
}

您還應該看到commit new work on block 1476 with 1 txs & 0 uncles您的交易何時包含在開采的區塊中。

引用自:https://ethereum.stackexchange.com/questions/2882