package gasprice

import "github.com/ethereum/go-ethereum/eth/gasprice"

Index

Variables

var (
	DefaultMaxPrice    = big.NewInt(500 * params.GWei)
	DefaultIgnorePrice = big.NewInt(2 * params.Wei)
)

Types

type Config

type Config struct {
	Blocks           int
	Percentile       int
	MaxHeaderHistory uint64
	MaxBlockHistory  uint64
	MaxPrice         *big.Int `toml:",omitempty"`
	IgnorePrice      *big.Int `toml:",omitempty"`
}

type Oracle

type Oracle struct {
	// contains filtered or unexported fields
}

Oracle recommends gas prices based on the content of recent blocks. Suitable for both light and full clients.

func NewOracle

func NewOracle(backend OracleBackend, params Config, startPrice *big.Int) *Oracle

NewOracle returns a new gasprice oracle which can recommend suitable gasprice for newly created transaction.

func (*Oracle) FeeHistory

func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedLastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, []*big.Int, []float64, error)

FeeHistory returns data relevant for fee estimation based on the specified range of blocks. The range can be specified either with absolute block numbers or ending with the latest or pending block. Backends may or may not support gathering data from the pending block or blocks older than a certain age (specified in maxHistory). The first block of the actually processed range is returned to avoid ambiguity when parts of the requested range are not available or when the head has changed during processing this request. Five arrays are returned based on the processed blocks:

Note: baseFee and blobBaseFee both include the next block after the newest of the returned range, because this value can be derived from the newest block.

func (*Oracle) SuggestTipCap

func (oracle *Oracle) SuggestTipCap(ctx context.Context) (*big.Int, error)

SuggestTipCap returns a tip cap so that newly created transaction can have a very high chance to be included in the following blocks.

Note, for legacy transactions and the legacy eth_gasPrice RPC call, it will be necessary to add the basefee to the returned number to fall back to the legacy behavior.

type OracleBackend

type OracleBackend interface {
	HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
	BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
	GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
	Pending() (*types.Block, types.Receipts, *state.StateDB)
	ChainConfig() *params.ChainConfig
	SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
}

OracleBackend includes all necessary background APIs for oracle.

Source Files

feehistory.go gasprice.go

Version
v1.16.1 (latest)
Published
Jul 2, 2025
Platform
linux/amd64
Imports
20 packages
Last checked
2 days ago

Tools for package owners.