Skip to content

TypeError: Transaction had invalid fields: {'to': '0x0d8ce2a99bb6e3b7db580ed848240e4a0f9ae153'} #211

Open
@woshidama323

Description

  • Version: 5.31.1
  • Python: 3.9.6
  • OS: linux
  • pip freeze output
aiohttp==3.8.1
aiosignal==1.2.0
async-timeout==4.0.2
attrs==22.1.0
aws-cdk-lib==2.41.0
base58==2.1.1
bitarray==2.6.0
cached-property==1.5.2
cattrs==22.1.0
certifi==2021.5.30
charset-normalizer==2.1.1
constructs==10.1.97
contourpy==1.0.6
crytic-compile==0.2.3
cycler==0.11.0
cytoolz==0.12.0
docopt==0.6.2
ecdsa==0.18.0
eth-abi==2.2.0
eth-account==0.5.9
eth-bloom==1.0.4
eth-hash==0.3.3
eth-keyfile==0.5.1
eth-keys==0.3.4
eth-rlp==0.2.1
eth-typing==2.3.0
eth-utils==1.10.0
exceptiongroup==1.0.0rc9
fonttools==4.38.0
frozenlist==1.3.1
hexbytes==0.3.0
idna==3.4
ipfshttpclient==0.8.0a2
jsii==1.67.0
jsonschema==4.16.0
kiwisolver==1.4.4
lru-dict==1.1.8
matplotlib==3.6.1
multiaddr==0.0.9
multidict==6.0.2
mypy-extensions==0.4.3
netaddr==0.8.0
numpy==1.23.4
openstep-parser==1.5.3
packaging==21.3
parsimonious==0.8.1
pbxproj==3.2.3
Pillow==9.3.0
prettytable==3.3.0
protobuf==3.19.5
publication==0.0.3
py-ecc==6.0.0
py-evm==0.6.0a1
pycryptodome==3.15.0
pyethash==0.1.27
pyparsing==3.0.9
pyrsistent==0.18.1
pysha3==1.0.2
python-dateutil==2.8.2
requests==2.28.1
rlp==2.0.1
six==1.16.0
slither-analyzer==0.8.3
solc-select==0.2.1
sortedcontainers==2.4.0
toolz==0.12.0
trie==2.0.2
typeguard==2.13.3
typing-extensions==4.3.0
urllib3==1.26.12
varint==1.0.2
wcwidth==0.2.5
web3==5.31.1
websockets==9.1
yarl==1.8.1

What was wrong?

Please include any of the following that are applicable:

description:
when trying to sign with sign_transaction offline, I got such errors bellow:
TypeError: Transaction had invalid fields: {'to': '0x0d8ce2a99bb6e3b7db580ed848240e4a0f9ae153'}

Here is the whole output

>>> stx = {'gasPrice': 5000000000, 'nonce': 431, 'to': '0x0d8ce2a99bb6e3b7db580ed848240e4a0f9ae153', 'value': 0, 'data': '0xa9059cbb0000000000000000000000002ff22e41447be8acadbfab0c95968263da15dd1a000000000000000000000000000000000000000000000000c3e3df74074f3f51', 'gas': 200000, 'chainId': 56}
>>> 
>>> import web3
>>> from web3.auto import w3
>>> w3.eth.account.sign_transaction(transaction_dict, "<private key>")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'transaction_dict' is not defined
>>> w3.eth.account.sign_transaction(stx, "<private key>")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eth_utils/decorators.py", line 18, in _wrapper
    return self.method(obj, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eth_account/account.py", line 748, in sign_transaction
    ) = sign_transaction_dict(account._key_obj, sanitized_transaction)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eth_account/_utils/signing.py", line 32, in sign_transaction_dict
    unsigned_transaction = serializable_unsigned_transaction_from_dict(transaction_dict)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eth_account/_utils/legacy_transactions.py", line 44, in serializable_unsigned_transaction_from_dict
    assert_valid_fields(transaction_dict)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/eth_account/_utils/legacy_transactions.py", line 114, in assert_valid_fields
    raise TypeError("Transaction had invalid fields: %r" % invalid)
TypeError: Transaction had invalid fields: {'to': '0x0d8ce2a99bb6e3b7db580ed848240e4a0f9ae153'}

But if i change the to field with "0xdd8ce2a99bb6e3b7db580ed848240e4a0f9ae153" (here i changed 0x0 to 0xd)
It works well

Guess the web3.py cannot handle such 0x0 prefix address well ?

How can it be fixed?

Fill this section in if you know how this could or should be fixed.
None

Note: We prefer to use issues to track our work. If you think you've encountered a bug in web3py or
have a feature request, you're in the right place. If you have implementation or usage questions,
please refer to our documentation and/or join the conversation
on discord.

Metadata

Assignees

No one assigned

    Labels

    p3normal

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions