eth_estimateGas - Somnia

Example code for the eth_estimateGas JSON-RPC method. Complete guide on how to use eth_estimateGas JSON-RPC in GetBlock Web3 documentation.

This method generates an estimate of how much gas is necessary to complete a transaction on the Somnia network. This is essential for setting appropriate gas limits. Somnia's IceDB provides deterministic performance, enabling more accurate gas estimation than traditional blockchains.

Parameters

Parameter
Type
Required
Description

transaction

object

Yes

Transaction call object

blockNumber

string

No

Block number in hex, or "latest" (default)

Transaction Object

Field
Type
Required
Description

from

string

No

Sender address

to

string

No

Recipient address

gas

string

No

Gas limit

gasPrice

string

No

Gas price

value

string

No

Value to send

data

string

No

Transaction data

Request Example

cURL
curl -X POST https://go.getblock.io/<ACCESS-TOKEN>/ \
-H "Content-Type: application/json" \
-d '{
  "jsonrpc": "2.0",
  "id": "getblock.io",
  "method": "eth_estimateGas",
  "params": [
    {
      "from": "0x742d35Cc6634C0532925a3b844Bc9e7595f8bB45",
      "to": "0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199",
      "value": "0xde0b6b3a7640000"
    }
  ]
}'

Response Example

Response Parameters

Parameter
Type
Description

result

string

Gas estimate in hex (0x5208 = 21000 for simple transfer)

Use Cases

  • Calculate transaction costs before sending

  • Set appropriate gas limits

  • Budget gas for complex contract interactions

  • Optimize transaction parameters

  • Prevent out-of-gas errors

Error Handling

Error Code
Description

-32602

Invalid params - malformed transaction object

-32603

Internal error - execution reverted

-32000

Execution error - insufficient funds or revert

SDK Integration

Last updated

Was this helpful?