Skip to content

Instantly share code, notes, and snippets.

@root-tanishq
Created April 24, 2024 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save root-tanishq/79c8ef4c126c118ae6d4ef4dfc7d67c4 to your computer and use it in GitHub Desktop.
Save root-tanishq/79c8ef4c126c118ae6d4ef4dfc7d67c4 to your computer and use it in GitHub Desktop.
import rlp
from eth_utils import keccak, to_checksum_address, to_bytes
def mk_contract_address(sender: str, nonce: int) -> str:
sender_bytes = to_bytes(hexstr=sender)
raw = rlp.encode([sender_bytes, nonce])
h = keccak(raw)
address_bytes = h[12:]
return to_checksum_address(address_bytes)
print(mk_contract_address('0xaDb67e10Fa330db49e98201B4c5F19356CfA3f59',0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment