Created
January 20, 2019 16:14
-
-
Save tommyz7/1e8e48ca32254696b8bb08bd29571d09 to your computer and use it in GitHub Desktop.
Predict an address of newly deployed smart contract
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
| 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