Hi, I believe there is an error with the encode_structured_data function. So I currently have a structured_message that I am trying to encode and generate a signature for:
TypeError: Object of type bytes is not JSON serializable
I then converted the listingsRoot to a hexstring and tried submitting it only to get the following error:
``TypeError: Value oflistingsRoot(0x5057c9046ab5607abbe1a5f31836cbf96f536488060fd6b1b4df375772ab050e) in the structOrderis of the type<class 'str'>`, but expected bytes32 value
I am not sure if this is a bug because it keeps going and I can't seem to encode the structured message.
### Code that produced the error
```python
listings_root_bytes32 = bytes.fromhex('5057c9046ab5607abbe1a5f31836cbf96f536488060fd6b1b4df375772ab050e')
# Define the structured message with bytes32 type
structured_message = {
'types': {
'EIP712Domain': [
{'name': 'name', 'type': 'string'},
{'name': 'version', 'type': 'string'},
{'name': 'chainId', 'type': 'uint256'},
{'name': 'verifyingContract', 'type': 'address'}
],
'Order': [
{'name': 'trader', 'type': 'address'},
{'name': 'collection', 'type': 'address'},
{'name': 'listingsRoot', 'type': 'bytes32'},
{'name': 'numberOfListings', 'type': 'uint256'},
{'name': 'expirationTime', 'type': 'uint256'},
{'name': 'assetType', 'type': 'uint8'},
{'name': 'makerFee', 'type': 'FeeRate'},
{'name': 'salt', 'type': 'uint256'},
{'name': 'orderType', 'type': 'uint8'},
{'name': 'nonce', 'type': 'uint256'}
],
'FeeRate': [
{'name': 'recipient', 'type': 'address'},
{'name': 'rate', 'type': 'uint16'}
]
},
'primaryType': 'Order',
'domain': {
'name': 'Blur Exchange',
'version': '1.0',
'chainId': 81457,
'verifyingContract': '0x0f41639352b190f352baddd32856038f1c230ced'
},
'message': {
'trader': '0x2f7a8981218c5981a2af8db44f2ca8045d4017c5',
'collection': '0x122a7d84504547e99664ad525329ffb5d9edc135',
'listingsRoot': '0x5057c9046ab5607abbe1a5f31836cbf96f536488060fd6b1b4df375772ab050e',
# Convert bytes to hex string
'numberOfListings': 1,
'expirationTime': 1748319197,
'assetType': 0,
'makerFee': {
'recipient': '0x0000000000000000000000000000000000000000',
'rate': 0
},
'salt': 132846178078048760365904106361965761667,
'orderType': 1,
'nonce': 0
}
}
# Encode the structured message
encoded_data = encode_structured_data(primitive=structured_message)
Full error output
TypeError: Value of `listingsRoot` (0x5057c9046ab5607abbe1a5f31836cbf96f536488060fd6b1b4df375772ab050e) in the struct `Order` is of the type `<class 'str'>`, but expected bytes32 value
Fill this section in if you know how this could or should be fixed
We recently removed encode_structured_data in favor of encode_typed_data. Docs here. Try giving that a shot instead. If you need further help, feel free to post in our discord, as this is a usage question, not a problem with the library.
What happened?
Hi, I believe there is an error with the
encode_structured_data
function. So I currently have a structured_message that I am trying to encode and generate a signature for:however, this generates me an error that says:
I then converted the
listingsRoot
to a hexstring and tried submitting it only to get the following error:``TypeError: Value of
listingsRoot(0x5057c9046ab5607abbe1a5f31836cbf96f536488060fd6b1b4df375772ab050e) in the struct
Orderis of the type
<class 'str'>`, but expected bytes32 valueFull error output
Fill this section in if you know how this could or should be fixed
No response
eth-account Version
0.5.3
Python Version
3.10
Operating System
osx
Output from
pip freeze