testnet
GitHub

Estimate Gas

EstimateGas(tx map[string]interface{}) (string, error)

Generates and returns an estimate of how much gas is necessary to allow the transaction to complete.

Parameters

Name Type Required Description
tx map[string]interface{} Transaction object (to, data, value)

Returns

Type: string

Estimated gas amount (hex)

Examples

Estimate transfer cost

tx := map[string]interface{}{
    "to": "0x...",
    "value": "0x1",
}
gas, _ := rpc.EstimateGas(tx)
fmt.Println("Gas needed:", gas)
Source:
ESC
Type to search