solidity部分代码: function keccak256_encode()public view returns (address result){ uint256 ki = uint256(0xD96446bA52F0d02544AFE9020d902e36b68B8641); result = address(uint256(keccak256(abi.encode(ki)))); }
//返回结果,地址值为: 0xb805F603f0E8c36a08cFE06846F4fe1f14720119
python部分代码:
from web3 import Web3
from eth_utils import (
is_checksum_address,
to_bytes,
to_hex,
)
bsc = 'https://bsc-dataseed2.defibit.io/'
web3 = Web3(Web3.HTTPProvider(bsc))
keccak256_str='0x000000000000000000000000d96446ba52f0d02544afe9020d902e36b68b8641'
mimi = web3.sha3(text=keccak256_str)
print('mimi:',to_hex(mimi))
###返回结果: 0x075220618a98185871f1f88340decab9f532f9e3bfb5a6c1a9af961bb65fd448
###截取地址: 0x40decab9f532f9e3bfb5a6c1a9af961bb65fd448
solidity结果:0xb805F603f0E8c36a08cFE06846F4fe1f14720119 python结果:0x40decab9f532f9e3bfb5a6c1a9af961bb65fd448
请教下大佬们,请问下solidity和python的keccak256结果为何不一致,如何让python的运行结果与solidity的一致,谢谢。