From 8bc3cc471bbc3a15d058aea5bd143920f840eff5 Mon Sep 17 00:00:00 2001 From: yihuang Date: Fri, 24 Dec 2021 00:12:05 +0800 Subject: [PATCH] fix: web3 client doesn't expect a nil baseFeePerGas (#854) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: #853 Solution: - only set baseFeePerGas when base fee is not nil. Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> --- rpc/ethereum/types/utils.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rpc/ethereum/types/utils.go b/rpc/ethereum/types/utils.go index add10668..290af5eb 100644 --- a/rpc/ethereum/types/utils.go +++ b/rpc/ethereum/types/utils.go @@ -98,7 +98,7 @@ func FormatBlock( transactionsRoot = common.BytesToHash(header.DataHash) } - return map[string]interface{}{ + result := map[string]interface{}{ "number": hexutil.Uint64(header.Height), "hash": hexutil.Bytes(header.Hash()), "parentHash": common.BytesToHash(header.LastBlockID.Hash.Bytes()), @@ -116,12 +116,17 @@ func FormatBlock( "timestamp": hexutil.Uint64(header.Time.Unix()), "transactionsRoot": transactionsRoot, "receiptsRoot": ethtypes.EmptyRootHash, - "baseFeePerGas": (*hexutil.Big)(baseFee), "uncles": []common.Hash{}, "transactions": transactions, "totalDifficulty": (*hexutil.Big)(big.NewInt(0)), } + + if baseFee != nil { + result["baseFeePerGas"] = (*hexutil.Big)(baseFee) + } + + return result } type DataError interface {