Decode input data for a contract creation transaction
Asked Answered
B

1

5

So I have successfully used the function decode_function_input(txn.input) to decode the input data for most transactions except for contract creation input data. Is there a simple and straightforward way to achieve this for contract creation using web3.py?

The hash in 'event' is not a contract creation hash, however, it seems not to work as well. Any insight to get around this would be appreciated.

Method tried:

event = "0x1113a21473aa89fcce64835d267dd480c9f0339411c676b1f22f11ae8e876b63"
txn = web3.eth.get_transaction(event)                                  
txnInput = routerContract.decode_function_input(txn.input) 
Buxom answered 26/10, 2021 at 22:45 Comment(0)
N
1

I couldn't find a method in web3.py to decode contract creation transactions. Instead, you can use web3-input-decoder to do it. The following example from the project's GitHub page shows how to decode a normal transaction and a contract creation transaction.

import json
import urllib.request
from web3_input_decoder import decode_constructor, decode_function
f = urllib.request.urlopen("https://api.etherscan.io/api?module=contract&action=getabi&address=0xdac17f958d2ee523a2206206994597c13d831ec7")
TETHER_ABI = json.loads(json.load(f)["result"])
decode_function(
    TETHER_ABI, "0xa9059cbb000000000000000000000000f050227be1a7ce587aa83d5013f900dbc3be0611000000000000000000000000000000000000000000000000000000000ecdd350",
)
decode_constructor(
    TETHER_ABI, "000000000000000000000000000000000000000000000000000000174876e800000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a546574686572205553440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000045553445400000000000000000000000000000000000000000000000000000000"
)
Narcho answered 17/9, 2023 at 20:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.