Skip to content

Instantly share code, notes, and snippets.

@tommyz7
Created January 20, 2019 16:14
Show Gist options
  • Select an option

  • Save tommyz7/1e8e48ca32254696b8bb08bd29571d09 to your computer and use it in GitHub Desktop.

Select an option

Save tommyz7/1e8e48ca32254696b8bb08bd29571d09 to your computer and use it in GitHub Desktop.
Predict an address of newly deployed smart contract
import rlp
from eth_utils import keccak, to_checksum_address, to_bytes
def predict_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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment