Skip to content

ethclient: BlockByNumber cannot handle pending block #25537

Closed
@757566833

Description

@757566833

System information

Geth version: ethereum/client-go:alltools-v1.10.20
OS & Version:Linux

github.com/ethereum/go-ethereum v1.10.20

Expected behaviour

unmarshal

Actual behaviour

cannot unmarshal

Steps to reproduce the behaviour

import (
	"github.com/ethereum/go-ethereum/ethclient"
)
client, err := ethclient.Dial("rpc")
client.BlockByNumber(context.Background(), new(big.Int).SetInt64(-1))

Backtrace

[backtrace]

When submitting logs: please submit them as text and not screenshots.

json: cannot unmarshal non-string into Go struct field rpcBlock.hash of type common.Hash

i want to get pending tx by ethclient

raw

{
    "baseFeePerGas":"0x7",
    "difficulty":"0x747e5",
    "extraData":"0xd883010a14846765746888676f312e31382e33856c696e7578",
    "gasLimit":"0x1c9c380",
    "gasUsed":"0xa410",
    "hash":null,
    "logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "miner":null,
    "mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
    "nonce":null,
    "number":"0x17af0",
    "parentHash":"0x5e572fe3ce0eb8a4500e9484761d1f0ba7fe50cb8f4741c3bed7550a89e13a1e",
    "receiptsRoot":"0x75308898d571eafb5cd8cde8278bf5b3d13c5f6ec074926de3bb895b519264e1",
    "sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size":"0x31c",
    "stateRoot":"0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp":"0x62fc648c",
    "totalDifficulty":null,
    "transactions":[
        {
            "blockHash":"0x653ca39fd6ab97ab1f88f0a1d6c1d38d8072ea4bd0b23d3410b548384a9d3b93",
            "blockNumber":"0x17af0",
            "from":"0xfe6154079ef3342e72b119636e839f1bb61cf29e",
            "gas":"0x5208",
            "gasPrice":"0x3b9aca00",
            "maxFeePerGas":"0x3b9aca00",
            "maxPriorityFeePerGas":"0x3b9aca00",
            "hash":"0x3a1ca417aef3418f209feb14fc89ae97ad85a72e32d7f9e332ceea9cbd08ae5b",
            "input":"0x",
            "nonce":"0x9",
            "to":"0x2a61b29ab416e0239e20f5bccf7319dab9cb3982",
            "transactionIndex":"0x0",
            "value":"0xde0b6b3a7640000",
            "type":"0x2",
            "accessList":[

            ],
            "chainId":"0x7c6807fe612",
            "v":"0x1",
            "r":"0xf3a980088d625acdf948833298cc734e1aff0a942b16bb9223cfe280b981d4c4",
            "s":"0x29b0052a2a21a7ee048289aa75b6e9cc33d723c1162cdcd27a2225ac763cc579"
        },
        {
            "blockHash":"0x653ca39fd6ab97ab1f88f0a1d6c1d38d8072ea4bd0b23d3410b548384a9d3b93",
            "blockNumber":"0x17af0",
            "from":"0xfe6154079ef3342e72b119636e839f1bb61cf29e",
            "gas":"0x5208",
            "gasPrice":"0x2540be400",
            "maxFeePerGas":"0x2540be400",
            "maxPriorityFeePerGas":"0x2540be400",
            "hash":"0xd3c0ab01e16e88193c7af35ac9cd5635ad3841d5496f58c3386f730a25681ef2",
            "input":"0x",
            "nonce":"0xa",
            "to":"0x2a61b29ab416e0239e20f5bccf7319dab9cb3982",
            "transactionIndex":"0x1",
            "value":"0x1bc16d674ec80000",
            "type":"0x2",
            "accessList":[

            ],
            "chainId":"0x7c6807fe612",
            "v":"0x0",
            "r":"0x91f640d98ef1e683c7acce05e87b44af345a83a03231ef4e9110dbbd77f8c2b3",
            "s":"0x18215088ecaba584ea6c16ab5ea0cee6b8c5b97afb9b682d99b00d8e1231504c"
        }
    ],
    "transactionsRoot":"0xa84ebbdec21a798e52af4978b9fb56b9d964b5a8ae5de7f016c633d7a7768bfe",
    "uncles":[

    ]
}

but body (rpcblock)

// ethclient line 104
type rpcBlock struct {
	Hash         common.Hash      `json:"hash"`
	Transactions []rpcTransaction `json:"transactions"`
	UncleHashes  []common.Hash    `json:"uncles"`
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions