[英]Ethereum Web3.js : Intrinsic Gas too low
在過去的幾天里,我一直試圖在以太坊測試網 Rinkeby 上發送交易,無論我增加多少 gas 和 gwei,都會不斷收到這個錯誤。 "Unhandled rejection Error: Returned error: intrinsic gas too low"
我發送的數據是:-
"0x7b22416e7377657273223a5b7b225175657374696f6e223a2231222c22416e73776572223a2234227d2c7b225175657374696f6e223a2232222c22416e73776572223a2234227d2c7b225175657374696f6e223a2233222c22416e73776572223a2234227d2c7b225175657374696f6e223a2234222c22416e73776572223a2234227d2c7b225175657374696f6e223a2235222c22416e73776572223a2234227d2c7b225175657374696f6e223a2236222c22416e73776572223a2234227d5d7d"
在它被轉換為十六進制之后。
我在下面添加了我的代碼。
var number = web3.eth.getTransactionCount(address).then(function(count) { console.log("Count " + count); var privateKey = new EthJS.Buffer.Buffer(privateKey, 'hex'); console.log(web3.utils.toHex(finalAnswers)); var rawTx = { nonce: web3.utils.toHex(count), to: '0xF1aA87F7058e5ABE561cCe8A466eE1CC17d69639', value: 0, data: web3.utils.toHex(finalAnswers), gas: 50000, gasPrice: web3.utils.toWei('300', 'gwei') }; var tx = new EthJS.Tx(rawTx); tx.sign(privateKey); var serializedTx = tx.serialize(); web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')).on('receipt', console.log); });
就我而言,某些方法必須手動設置 Gas Limit,因此我切換到交易的默認 Gas Limit。 在 pancakeswap 參考中,它是 20,000 個單位
https:\/\/github.com\/pancakeswap\/pancake-frontend\/blob\/master\/src\/config\/index.ts#L31<\/a>您可以將 prop 調整為
gas<\/code>
代碼如下所示:
const txReceipt = await callWithGasPrice(
wethContract,
"deposit",
undefined,
{
value: `0x${inputAmount.raw.toString(16)}`,
gasPrice,
gasLimit: DEFAULT_GAS_LIMIT,
}
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.