Skip to content

Commit

Permalink
Handle "null" result from eth_getTransactionCount method
Browse files Browse the repository at this point in the history
Fixes error: getting transaction count: json: cannot unmarshal non-string into Go value of type hexutil.Uint

Example payload:

curl -X 'POST' -d '{"jsonrpc":"2.0","id":20,"method":"eth_getBlockTransactionCountByHash","params":["0x75e20b44ed45bd9e8d261385fb2cb1886c31f91b8bafad9cc38addebf1f950ed"]}' -H 'Content-Type: application/json' -H 'User-Agent: sequence/node-check' 'https://little-crimson-energy.quiknode.pro/***/'

time: 13.592958ms
status: HTTP 200
body: {"jsonrpc":"2.0","id":20,"result":null}
  • Loading branch information
VojtechVitek committed Jun 7, 2024
1 parent 7be8500 commit 0996b77
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ethrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func hexIntoBigInt(message json.RawMessage, ret **big.Int) error {
}

func hexIntoUint64(message json.RawMessage, ret *uint64) error {
if len(message) == 4 && string(message) == "null" {
*ret = 0
return nil
}

var result hexutil.Uint64
if err := json.Unmarshal(message, &result); err != nil {
return err
Expand All @@ -136,6 +141,11 @@ func hexIntoUint64(message json.RawMessage, ret *uint64) error {
}

func hexIntoUint(message json.RawMessage, ret *uint) error {
if len(message) == 4 && string(message) == "null" {
*ret = 0
return nil
}

var result hexutil.Uint
if err := json.Unmarshal(message, &result); err != nil {
return err
Expand Down

0 comments on commit 0996b77

Please sign in to comment.