2

I want to run Soliditykeccak256(abi.encodePacked(challenge_number, msg.sender, nonce)) where nonce is uint256, challenge_digest is bytes32, challenge_number bytes32, testTarget is uint.

What's the analog of this in python? I've already connected to the contract with my metamask account through Python.

2

Web3.solidityKeccak(abi_types, value) should do the job

Examples:

Web3.solidityKeccak(['bool'], [True])
# HexBytes("0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2")

Web3.solidityKeccak(['uint8', 'uint8', 'uint8'], [97, 98, 99])
# HexBytes("0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")

Web3.solidityKeccak(['uint8[]'], [[97, 98, 99]])
# HexBytes("0x233002c671295529bcc50b76a2ef2b0de2dac2d93945fca745255de1a9e4017e")

Web3.solidityKeccak(['address'], ["0x49EdDD3769c0712032808D86597B84ac5c2F5614"])
# HexBytes("0x2ff37b5607484cd4eecf6d13292e22bd6e5401eaffcc07e279583bc742c68882")

Web3.solidityKeccak(['address'], ["ethereumfoundation.eth"])
# HexBytes("0x913c99ea930c78868f1535d34cd705ab85929b2eaaf70fcd09677ecd6e5d75e9")
| improve this answer | |

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.