Contract-Debugging

如何查詢 ERC20 交易的estimatedGas?

  • June 14, 2022

這是我進行的 json-rpc 呼叫

{
 "jsonrpc": "2.0", 
 "method": "eth_estimateGas", 
 "params": [
  {
   "from": "0x71C7656EC7ab88b098defB751B7401B5f6d8976F", 
   "to": "0xdac17f958d2ee523a2206206994597c13d831ec7", //USDT
   "data": "0xa9059cbb00000000000000000000000044C004Fbbb407a45ea731AbE01E0CE348f311b9f000000000000000000000000000003e8" 
  }
 ],
 "id": "1"
}

但我不斷收到此錯誤

{ 
 "jsonrpc": "2.0", 
 "id": "1", 
 "error": {
    "code": "-32000", 
    "message": "execution reverted"
 }
}

from 地址有足夠的 USDT(大約 10k USDT),tx 的價值是 1000 USDT。

您沒有在value參數中正確編碼數據。一定是uint256

所以正確的有效載荷應該使用這個數據字元串:

"data": "0xa9059cbb00000000000000000000000044c004fbbb407a45ea731abe01e0ce348f311b9f00000000000000000000000000000000000000000000000000000000000003e8"

調試提示:

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