I’m curious when i see some fantastic projects, so I’m doing some experiments to find out the method which used by Base to generate the contract address.
Tried with two different methods, and I’ve deployed a contract on Base Chain to validate.
def predict_contract_address(deployer_address, nonce):
encoded = Web3.solidity_keccak(['address', 'uint256'], [deployer_address, nonce])
contract_address = Web3.to_checksum_address(encoded[-20:])
return contract_address
This method returning 0xc989DF16dc2026D73f018158cEad7AAf3508Dd3e which is not matching the actual address. The following is second method.
def pca(deployer_address, nonce):
return to_checksum_address(keccak(rlp.encode([deployer_address, nonce]))[-20:])
This method returning address 0xdEca8F8D505Ba2BF3B9d4120f66B3Ec9e49393fb according to the guideline which is wrong also. Both using nonce 0 for calculation. Tx Hash of actual contract deployment – 0x1c2e239387c9e6609f1e82900080ab9606e42d5c33074d1e95431817698152e0
Spencer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.