diff --git a/evmrpc/info.go b/evmrpc/info.go index f1c0313d45..d795261031 100644 --- a/evmrpc/info.go +++ b/evmrpc/info.go @@ -175,6 +175,20 @@ func (i *InfoAPI) FeeHistory(ctx context.Context, blockCount math.HexOrDecimal64 return result, nil } +func (i *InfoAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) { + startTime := time.Now() + defer recordMetrics("eth_maxPriorityFeePerGas", i.connectionType, startTime, true) + feeHist, err := i.FeeHistory(ctx, 1, rpc.LatestBlockNumber, []float64{0.5}) + if err != nil { + return nil, err + } + if len(feeHist.Reward) == 0 || len(feeHist.Reward[0]) == 0 { + // if there is no EVM tx in the most recent block, return 0 + return (*hexutil.Big)(big.NewInt(0)), nil + } + return (*hexutil.Big)(feeHist.Reward[0][0].ToInt()), nil +} + func (i *InfoAPI) safeGetBaseFee(targetHeight int64) (res *big.Int) { defer func() { if err := recover(); err != nil { diff --git a/evmrpc/info_test.go b/evmrpc/info_test.go index e55538007f..b56f9e2c6d 100644 --- a/evmrpc/info_test.go +++ b/evmrpc/info_test.go @@ -12,6 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/go-bip39" "github.com/sei-protocol/sei-chain/evmrpc" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -158,3 +159,10 @@ func TestCalculatePercentiles(t *testing.T) { require.Equal(t, big.NewInt(3), result[1].ToInt()) require.Equal(t, big.NewInt(10), result[2].ToInt()) } + +func TestMaxPriorityFeePerGas(t *testing.T) { + Ctx = Ctx.WithBlockHeight(1) + // Mimic request sending and handle the response + resObj := sendRequestGood(t, "maxPriorityFeePerGas") + assert.Equal(t, "0xa", resObj["result"]) +}