Created
April 21, 2023 23:57
-
-
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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