-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot encode bytes32 in structured data #90
Comments
Same happened to me with |
I got the same error too when using Erroreth_account/messages.py", line 146, in encode_structured_data
message_string = json.dumps(primitive)
TypeError: Object of type bytes is not JSON serializable Personally I believe: The current implementation
Thus I second @jstoxrocky 's solution at #91 |
Try adding a |
also interested in the solution |
That won't work either:
|
I think #91 is a good change, thanks @jstoxrocky! Sorry it has taken a minute to get to this. I think something that may be missing (from a quick peek) is that we would need validation so that a I think I'm OK with merging #91 in as a bug fix but we should definitely add a note there that types are not yet validated. I will reply in the PR as well and I can create an issue to add the type validation so we can track it. Unfortunately I may not get to it for a bit but I appreciate the recent attention to this older issue. Seems like encoded data needs some love if anyone is looking for some contributions. |
closed by #91 |
any chance to get a new release with this fix? |
Thanks for the ping! Yep, look for one next week! |
@joaquim-verges |
Solution for eth_account < 0.6.0:
use
|
What was wrong?
I cannot encode
bytes32
in structured data. I am attempting to pass a struct containing a variable I want encoded asbytes32
toeth_account.messages.encode_structured_data
. I am passing this struct toencode_structured_data
as a Python dictionary. Including mybytes32
variable as a bytestring causes a JSON serialization error (eth_account/messages.py:143). Passing this variable as a hex string throws a TypeError (eth_account/_utils/structured_data/hashing.py:250).Code that produced the error
Full error output
Expected Result
It can definitely be done and should equal something like this:
How can it be fixed?
I'm posting an issue first before attempting to fix to ask yall how best you think this can be solved? Why do we need to
json.dumps
? Seems like thats a blocker since bytes can't be easily serialized into JSON.PR #91
The text was updated successfully, but these errors were encountered: