ethereum / go-ethereum

Go implementation of the Ethereum protocol
https://geth.ethereum.org
GNU Lesser General Public License v3.0
47.45k stars 20.08k forks source link

Possibility to perform transactions replay intra-block when using CallContract #30598

Open 0xgiantkoala opened 1 week ago

0xgiantkoala commented 1 week ago

Currently, gethclient.CallContract supports blockNumber override.

However, there are cases where I am interested in reading/simulating stuff intra block. (ie: top of block T and then replay first N transactions from block T + 1).

Basically, I need Foundry's createSelectFork("rpc", "txHash") in GETH.

Is there an official and idiomatic way that allows me to do this (without needing to fork go-ethereum and implement the replay stuff myself) ?

s1na commented 1 week ago

The debug_traceCall method does support txIndex field. It is not available in ethclient tho unfortunately. If you directly called the rpc method you can:

debug_traceCall({ from: ..., to: ..., }, "0xblocknum", { "txIndex": 5, "tracer": "callTracer" })

I believe there was a PR for eth_call too but can't find it rn.

s1na commented 1 week ago

Alternatively you can use eth_simulateV1 and pass in all prior txes and add your call on top.

batu3H commented 2 minutes ago

to fix your trouble check this solution click maybe this will solve your problem.