diff --git a/rpc/eth_api.go b/rpc/eth_api.go index 71c72bb6..3f69b840 100644 --- a/rpc/eth_api.go +++ b/rpc/eth_api.go @@ -477,7 +477,7 @@ func (e *PublicEthAPI) doCall( // EstimateGas returns an estimate of gas usage for the given smart contract call. // It adds 1,000 gas to the returned value instead of using the gas adjustment // param from the SDK. -func (e *PublicEthAPI) EstimateGas(args CallArgs) (uint64, error) { +func (e *PublicEthAPI) EstimateGas(args CallArgs) (hexutil.Uint64, error) { simResponse, err := e.doCall(args, 0, big.NewInt(emint.DefaultRPCGasLimit)) if err != nil { return 0, err @@ -486,7 +486,8 @@ func (e *PublicEthAPI) EstimateGas(args CallArgs) (uint64, error) { // TODO: change 1000 buffer for more accurate buffer (eg: SDK's gasAdjusted) estimatedGas := simResponse.GasInfo.GasUsed gas := estimatedGas + 1000 - return gas, nil + + return hexutil.Uint64(gas), nil } // GetBlockByHash returns the block identified by hash. @@ -910,10 +911,11 @@ func (e *PublicEthAPI) generateFromArgs(args params.SendTxArgs) (*types.MsgEther Value: args.Value, Data: args.Data, } - gasLimit, err = e.EstimateGas(callArgs) + gl, err := e.EstimateGas(callArgs) if err != nil { return nil, err } + gasLimit = uint64(gl) } else { gasLimit = (uint64)(*args.Gas) } diff --git a/tests/rpc_test.go b/tests/rpc_test.go index 52e65bac..b89d2a65 100644 --- a/tests/rpc_test.go +++ b/tests/rpc_test.go @@ -655,3 +655,19 @@ func TestEth_GetTransactionCount(t *testing.T) { post := getNonce(t) require.Equal(t, prev, post-1) } + +func TestEth_EstimateGas(t *testing.T) { + from := getAddress(t) + param := make([]map[string]string, 1) + param[0] = make(map[string]string) + param[0]["from"] = "0x" + fmt.Sprintf("%x", from) + param[0]["to"] = "0x1122334455667788990011223344556677889900" + param[0]["value"] = "0x1" + rpcRes := call(t, "eth_estimateGas", param) + + var gas hexutil.Bytes + err := json.Unmarshal(rpcRes.Result, &gas) + require.NoError(t, err) + + require.Equal(t, hexutil.Bytes{0xf7, 0xa6}, gas) +}