0

The code I am having trouble with:

new_address = Web3.sha3(rlp.encode([normalize_address(accountAddress), nonce]))[-40:]
return '0x'+new_address

new_adress remains in bytes and I can't join it with 0x to produce normal string that will be the ethereum address. How to turn the bytes to string again? just new_address.decode() doesn't work and anything with utf-8 in it?

2

What is coming from:

new_adress = Web3.sha3(rlp.encode([normalize_address(accountAddress), nonce]))[-40:]

is type bytes, so you can do:

new_adress = web3.toHex(Web3.sha3(rlp.encode([normalize_address(accountAddress), nonce])))[-40:]
return '0x'+ new_adress

Hope this helps

  • Thank you, I'll try now...bytes yes, well this is from an old program from university of singapore or so called "Maian", I'm trying to check if my contract is "suicidal" (can be killed by hackers). Long story short: they are using Web3, and Web3 has specific keyword "encoding", the "encoding" is in bytes...web3-v4 doesn't have that so I just removed it but the variable new_address is still in bytes I guess. wil let you know later, 10x again. – kpopguy Sep 7 '18 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.