首页 > 解决方案 > 通过 eth 地址确定合约地址

问题描述

我想知道为什么我不能制作正确的以太坊合约地址。我遵循了https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed中的代码

结果:

def mk_contract_address(sender: str, nonce: int) -> str:
    """Create a contract address using eth-utils.

    # https://ethereum.stackexchange.com/a/761/620
    """
    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(to_checksum_address(mk_contract_address(to_checksum_address("0xCcE984c41630878b91E20c416dA3F308855E87E2"), 0)))

但返回:

0x10f08E4A832891f27A170031536cAdd3B190D250

正确的结果是:

0xdac17f958d2ee523a2206206994597c13d831ec7

问题是什么...

标签: python

解决方案


推荐阅读