My goal is to sign a message according to EIP712 from python code using an imported private key.

To construct the message to sign I am using: https://github.com/ConsenSys/py-eip712-structs

After creating the right object I can convert it either into:

# Into a message dict - domain required
my_msg = mine.to_message(domain)

# Into message JSON - domain required.
# This method converts bytes types for you, which the default JSON encoder won't handle.
my_msg_json = mine.to_message_json(domain)

# Into signable bytes - domain required
my_bytes = mine.signable_bytes(domain)

However - it is not clear to me how to proceed from here. Which of those 3 outputs can I use as input for: https://web3py.readthedocs.io/en/stable/web3.eth.account.html?highlight=sign#sign-a-message

Or do I need to use: https://web3py.readthedocs.io/en/stable/web3.eth.html?highlight=structured#web3.eth.Eth.sign_typed_data

Unfortunately this apparently just forwards to an PRC-node so it is not possible to use this from just within python.

1 Answer 1


"Signable bytes" may need to be passed into keccak256() if the EIP712 library didn't already do that for you. Sign the keccak256 hash to make a signature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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