Skip to content

Instantly share code, notes, and snippets.

@Aviksaikat
Created April 21, 2023 23:57
Show Gist options
  • Save Aviksaikat/76b3faa1de2ccc72449ecca95b7fac9e to your computer and use it in GitHub Desktop.
Save Aviksaikat/76b3faa1de2ccc72449ecca95b7fac9e to your computer and use it in GitHub Desktop.
Find out in advance the address of the smart contract I am going to deploy?
#!/usr/bin/python3
from brownie import web3, accounts
import rlp
def get_addr(attacker):
# Convert from hex to bytes. Be sure to drop the leading 0x
sender = bytes.fromhex(attacker.address[2:])
# The nonce is just a number
nonce = attacker.nonce
# Last 20 bytes means the last 40 characters in hexadecimal
contract_address = f"0x{web3.keccak(rlp.encode([sender, nonce])).hex()[-40:]}"
return contract_address
if __name__ == "__main__":
print(get_addr(accounts[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment