diff --git a/eth/api_backend.go b/eth/api_backend.go index 33fe4fe5d9..8bf91ba680 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -26,6 +26,7 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/consensus/misc/eip1559" "github.com/ethereum/go-ethereum/consensus/misc/eip4844" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/filtermaps" @@ -430,6 +431,13 @@ func (b *EthAPIBackend) FeeHistory(ctx context.Context, blockCount uint64, lastB return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles) } +func (b *EthAPIBackend) BaseFee(ctx context.Context) *big.Int { + if b.ChainConfig().IsLondon(b.CurrentHeader().Number) { + return eip1559.CalcBaseFee(b.ChainConfig(), b.CurrentHeader()) + } + return nil +} + func (b *EthAPIBackend) BlobBaseFee(ctx context.Context) *big.Int { if excess := b.CurrentHeader().ExcessBlobGas; excess != nil { return eip4844.CalcBlobFee(b.ChainConfig(), b.CurrentHeader()) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 6d38c6c7c8..68f56920ab 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -146,6 +146,11 @@ func (api *EthereumAPI) BlobBaseFee(ctx context.Context) *hexutil.Big { return (*hexutil.Big)(api.b.BlobBaseFee(ctx)) } +// BaseFee returns the base fee for the next block. +func (api *EthereumAPI) BaseFee(ctx context.Context) *hexutil.Big { + return (*hexutil.Big)(api.b.BaseFee(ctx)) +} + // Syncing returns false in case the node is currently not syncing with the network. It can be up-to-date or has not // yet received the latest block headers from its peers. In case it is synchronizing: // - startingBlock: block number this node started to synchronize from diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 63e75bd3e3..f191643ce2 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -500,6 +500,7 @@ func (b testBackend) FeeHistory(ctx context.Context, blockCount uint64, lastBloc return nil, nil, nil, nil, nil, nil, nil } func (b testBackend) BlobBaseFee(ctx context.Context) *big.Int { return new(big.Int) } +func (b testBackend) BaseFee(ctx context.Context) *big.Int { return new(big.Int) } func (b testBackend) ChainDb() ethdb.Database { return b.db } func (b testBackend) AccountManager() *accounts.Manager { return b.accman } func (b testBackend) ExtRPCEnabled() bool { return false } diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index af3d592b82..65112a5294 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -46,6 +46,7 @@ type Backend interface { SuggestGasTipCap(ctx context.Context) (*big.Int, error) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, []*big.Int, []float64, error) BlobBaseFee(ctx context.Context) *big.Int + BaseFee(ctx context.Context) *big.Int ChainDb() ethdb.Database AccountManager() *accounts.Manager ExtRPCEnabled() bool diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 30791f32b5..4b7774c9b7 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -318,6 +318,7 @@ func (b *backendMock) SuggestGasTipCap(ctx context.Context) (*big.Int, error) { return big.NewInt(42), nil } func (b *backendMock) BlobBaseFee(ctx context.Context) *big.Int { return big.NewInt(42) } +func (b *backendMock) BaseFee(ctx context.Context) *big.Int { return big.NewInt(42) } func (b *backendMock) CurrentHeader() *types.Header { return b.current } func (b *backendMock) ChainConfig() *params.ChainConfig { return b.config }