package gasestimator

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

Index

Functions

func Estimate

func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uint64) (uint64, []byte, error)

Estimate returns the lowest possible gas limit that allows the transaction to run successfully with the provided context options. It returns an error if the transaction would always revert, or if there are unexpected failures.

Types

type Options

type Options struct {
	Config         *params.ChainConfig      // Chain configuration for hard fork selection
	Chain          core.ChainContext        // Chain context to access past block hashes
	Header         *types.Header            // Header defining the block context to execute in
	State          *state.StateDB           // Pre-state on top of which to estimate the gas
	BlockOverrides *override.BlockOverrides // Block overrides to apply during the estimation

	ErrorRatio float64 // Allowed overestimation ratio for faster estimation termination
}

Options are the contextual parameters to execute the requested call.

Whilst it would be possible to pass a blockchain object that aggregates all these together, it would be excessively hard to test. Splitting the parts out allows testing without needing a proper live chain.

Source Files

gasestimator.go

Version
v1.15.11 (latest)
Published
May 5, 2025
Platform
linux/amd64
Imports
13 packages
Last checked
1 day ago

Tools for package owners.