Skip to content

Instantly share code, notes, and snippets.

@Aviksaikat
Created April 18, 2023 11:34
Show Gist options
  • Save Aviksaikat/009de442900f90a5a7d5a2ab594a5986 to your computer and use it in GitHub Desktop.
Save Aviksaikat/009de442900f90a5a7d5a2ab594a5986 to your computer and use it in GitHub Desktop.
Find the Bytecode of Ethereum Smart Contract by just it's address

You can use the web3.py or brownie module of python to achieve this

  • web3.py
from web3 import Web3

# Connect to custom RPC network
rpc_url = 'http://localhost:8545'  # Replace with your custom RPC URL
#chain_id = 1337  # Replace with your custom chain ID
web3 = Web3(Web3.HTTPProvider(rpc_url))

# Replace with the address of your deployed contract
contract_address = "0x876807312079af775c49c916856A2D65f904e612"
# Get teh byte code  
contract_bytecode = web3.eth.getCode(contract_address).hex()
print(f"Contract Bytecode: {contract_bytecode}")
  • brownie
from brownie import web3

contract_address = "0x876807312079af775c49c916856A2D65f904e612"
contract_bytecode = web3.eth.getCode(contract_address).hex()
print(f"Contract Bytecode: {contract_bytecode}")
  • Both will give the same result.

enter image description here

@Aviksaikat
Copy link
Author

for bownie make sure you have added the network in the brownie networks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment