var result json.RawMessage
invalidHash := "0x1234567890123456789012345678901234567890123456789012345678901234"
err = client.Call(&result, "eth_getTransactionReceipt", invalidHash)
if err != nil {
panic(err)
}
if result == nil {
panic("result should not be nil")
} else {
fmt.Printf("result: %s", result)
}
}
3. The go code panics since `result` is `nil`
4. Observe that running curl against the endpoint with the same RPC call properly returns the JSON field `"result": null`.
#### Fix
The error seems to be caused by a redundant reference operator in `rpc.Client.CallContext()`, when the JSON unmarshaller is called.
https://github.com/ethereum/go-ethereum/blob/dbd6c1324dda8bb93c7a8297446fce7998cab4e1/rpc/client.go#L348
Line 321 already checks that `result` is a pointer, so there shouldn’t be any need to reference it again.
https://github.com/ethereum/go-ethereum/blob/dbd6c1324dda8bb93c7a8297446fce7998cab4e1/rpc/client.go#L321-L323
Upon further investigation, it seems that nested pointers will be set to `nil` specifically when decoding `null` values (https://go.dev/src/encoding/json/decode.go#L424).
System information
Geth version:
v1.10.26
(but also in master branch)Expected behaviour
When
{"result": null}
is returned from a JSON RPC call inrpc.CallContext
, it should unmarshal into ajson.RawMessage
asjson.RawMessage("null")
.Actual behaviour
It actually gets unmarshalled as
nil
.Steps to reproduce the behaviour
--http
or--ws
RPC_ENDPOINT
environment variable to the URL of the networkresult
tojson.RawMessage("null")
import ( "encoding/json" "fmt" "os"
)
func main() { client, err := rpc.Dial(os.Getenv("RPC_ENDPOINT")) if err != nil { panic(err) } defer client.Close()
}