estimateFeesPerGas
Returns an estimate for the fees per gas for a transaction to be likely included in the next block
Loading...
Returns an estimate for the fees per gas for a transaction to be likely included in the next block
Returns an estimate for the fees per gas (in wei) for a transaction to be likely included in the next block.
maxFeePerGas & maxPriorityFeePerGas.gasPrice.Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"An example showing how to construct a public client and estimate fees for the next block.
import ( "context" "log"
"github.com/ChefBingbong/viem-go/actions/public" "github.com/ChefBingbong/viem-go/client" "github.com/ChefBingbong/viem-go/client/transport" "github.com/ChefBingbong/viem-go/chain/definitions")
ctx := context.Background()
publicClient, err := client.CreatePublicClient(client.PublicClientConfig{ Chain: definitions.Mainnet, Transport: transport.HTTP("https://eth.llamarpc.com"),})if err != nil { log.Fatal(err)}defer func() { _ = publicClient.Close() }()
fees, err := public.EstimateFeesPerGas(ctx, publicClient, public.EstimateFeesPerGasParameters{})if err != nil { log.Fatal(err)}log.Printf("Max fee per gas: %s", fees.MaxFeePerGas.String())log.Printf("Max priority fee per gas: %s", fees.MaxPriorityFeePerGas.String())*EstimateFeesPerGasReturnType
An object containing:
Type FeeValuesType - The type of fee values ("eip1559" or "legacy")MaxFeePerGas *big.Int - The max fee per gas (EIP-1559)MaxPriorityFeePerGas *big.Int - The max priority fee per gas (EIP-1559)GasPrice *big.Int - The gas price (legacy)Configuration options accepted by this action.
FeeValuesTypeFeeValuesTypeEIP1559The type of fee values to return.
fees, err := public.EstimateFeesPerGas(ctx, publicClient, public.EstimateFeesPerGasParameters{ Type: public.FeeValuesTypeLegacy,})*float641.2 (20% buffer)The multiplier applied to the base fee per gas (or gas price for legacy chains) when computing fees.
multiplier := 1.5fees, err := public.EstimateFeesPerGas(ctx, publicClient, public.EstimateFeesPerGasParameters{ BaseFeeMultiplier: &multiplier,})Underlying JSON-RPC methods used by this action.
Uses eth_getBlockByNumber, eth_maxPriorityFeePerGas, and eth_gasPrice to compute fees.