getFeeHistory
Returns a collection of historical gas information
Loading...
Returns a collection of historical gas information
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"An example showing how to request recent fee history and inspect the returned statistics.
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() }()
history, err := public.GetFeeHistory(ctx, publicClient, public.GetFeeHistoryParameters{ BlockCount: 4, RewardPercentiles: []float64{25, 75},})if err != nil { log.Fatal(err)}log.Printf("Fee history: %d blocks", len(history.Reward))formatters.FeeHistory
A formatted fee history containing:
BaseFeePerGas []*big.Int - Base fee per gas for each blockGasUsedRatio []float64 - Gas used ratio for each blockOldestBlock uint64 - Oldest block number in the rangeReward [][]*big.Int - Reward percentiles for each blockConfiguration options accepted by this action.
uint64The number of blocks in the requested range. Between 1 and 1024 blocks can be requested in a single query.
history, err := public.GetFeeHistory(ctx, publicClient, public.GetFeeHistoryParameters{ BlockCount: 4, RewardPercentiles: []float64{25, 75},})[]float64A monotonically increasing list of percentile values to sample from each block's effective priority fees per gas in ascending order, weighted by gas used.
history, err := public.GetFeeHistory(ctx, publicClient, public.GetFeeHistoryParameters{ BlockCount: 4, RewardPercentiles: []float64{25, 75},})*uint64The highest block number of the requested range.
blockNum := uint64(12345)history, err := public.GetFeeHistory(ctx, publicClient, public.GetFeeHistoryParameters{ BlockCount: 4, RewardPercentiles: []float64{25, 75}, BlockNumber: &blockNum,})BlockTag"latest"The highest block tag of the requested range (e.g., "latest").
history, err := public.GetFeeHistory(ctx, publicClient, public.GetFeeHistoryParameters{ BlockCount: 4, RewardPercentiles: []float64{25, 75}, BlockTag: public.BlockTagSafe,})Underlying JSON-RPC method used by this action.