3

I have a TX that wrap 0.23 ETH to WETH, I'am using trace_replayTransaction to get the stateDiff in this way:

curl https://eth-mainnet.alchemyapi.io/v2/<api-key> \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"method":"trace_replayTransaction","params":["0x3f2f797285255c88b016ba8ced7bb8865ba71107a6b57ba0dca5c29abe064801",["stateDiff"]],"id":1,"jsonrpc":"2.0"}'

The result is the following, we get the correct ETH balance changes, from minus to (417464533885416237-187069776364879837) will be equal to 230394757520536400, our 0.23 ETH we sent to wrap plus the miner fee

    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "output": "0x",
        "stateDiff": {
            "0x1fd502a324340454855ee0056ddf2ef0da6644ae": {
                "balance": {
                    "*": {
                        "from": "0x5cb21c82090732d", // 417464533885416237
                        "to": "0x2989af87070bfdd"    // 187069776364879837
                    }
                },
                ...

The problem is when I use trace_call to simulate the same transaction on the block before this tx got mine (although even using the "latest" block I got the same problem)

# the tx data come from the above tx 0x3f2f797285255c88b016ba8ced7bb8865ba71107a6b57ba0dca5c29abe064801
# where the value 0x3311fc80a570000 is equal to 0.23 ETH
# and the block 0xea25a7 is equal to 15345063 (a block before the tx's block)
curl https://eth-mainnet.alchemyapi.io/v2/<api-key> \
-X POST \
-H "Content-Type: application/json" \
-d '{"method":"trace_call",
    "params":[
      {"from":"0x1fd502a324340454855ee0056ddf2ef0da6644ae","to":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","value":"0x3311fc80a570000","data":"0xd0e30db0"},
      ["stateDiff"], "0xea25a7"],
    "id":1,
    "jsonrpc":"2.0"}'

The result for the stateDiff this time is a bit odd:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "output": "0x",
        "stateDiff": {
            "0x1fd502a324340454855ee0056ddf2ef0da6644ae": {
                "balance": {
                    "*": {
                        "from": "0x5cb21c82090732d",       // 417464533885416237
                        "to": "0xcfcbf46f8298e4633f3699fc" // 64309963288821133859991493116
                    }
                },

The balance before the tx, from = 417464533885416237, is correct, same as the trace_replayTransaction, 0.417 ETH, but the balance after the tx (the to) is too big, millions of ETH.

So simulating this tx with trace_call using the same inputs/address will result in a TX that didn't spent any ETH but gain some ETH from somewhere.

Is about the RPC? perhaps the the trace_call is unreliable? or is there some issues with the way I call this api?

Besically I need a way to simulate a transaction and get the stateDiff/balanceDiff before they are included in a block thus using the calldata and from/to address and simulate against the pending block.

1 Answer 1

4

Alchemist here.

Thanks for asking the question! We've checked your queries internally and it seems these responses are coming directly from our Ethereum client. So the incorrect numbers are not due to Alchemy and hence outside our control.

We're working with the Ethereum Client to resolve it and hope to give you a fix soon.

Thanks,

1
  • so what was the actual answer?
    – Risinek
    Aug 16 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.