0

I'm trying to replay transactions that exist in one chain on another.

I can replicate all transaction arguments that are available through eth_getTransactionByHash, but now need to sign the transaction. How do I extract the signing information from the committed transaction so that I'm able to resubmit with eth_sendRawTransaction.

Also welcome responses in web3.py, web3.js, ethers.js or any other preferred json-rpc SDK.

Existing code using web3.py that doesn't work:

tx = fallback_web3.eth.getTransaction(individual_tx_hash)
transaction = {
  "from": tx["from"],
  "to": tx["to"],
  "gas": tx["gas"],
  "gasPrice": tx["gasPrice"],
  "value": tx["value"],
  "nonce": tx["nonce"],
}
if "data" in tx:
  transaction["data"] = tx["data"]
w3.eth.sendTransaction(transaction)
15
  • 1
    Function eth_sendRawTransaction doesn't require you to pass the from value, as it is already embedded in the raw transaction itself (which you need to pass to this function). Sep 8 '20 at 10:55
  • @goodvibration exactly - and the question is how am I able to build up this raw transaction signature. I'm just using the RPC-API because it's most familiar across both JS/Python users.
    – Peteris
    Sep 8 '20 at 10:56
  • 1
    Just take the raw transaction as is. Sep 8 '20 at 11:00
  • 1
    Note that the signature of the transaction differs from one chain to another since the EIP-155 (eips.ethereum.org/EIPS/eip-155) to protect against replay attacks.
    – clement
    Sep 8 '20 at 11:07
  • 1
    You're right, if your two chains have the same chainId, then just sending the raw transaction should work.
    – clement
    Sep 8 '20 at 11:19
1

There is an undocumented eth_getRawTransactionByHash method now in geth nodes.

Get raw transaction from hash

After getting the raw transaction, it can be directly replayed using eth_sendRawTransaction as long as all the parameters are the same according to EIP-155 (https://eips.ethereum.org/EIPS/eip-155) (nonce, gasprice, startgas, to, value, data, chainid, 0, 0).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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