Skip to content
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

ContractFunction.call may fail as args and kwargs properties may be None #2541

Open
iwiwi opened this issue Jun 27, 2022 · 2 comments · May be fixed by #2545
Open

ContractFunction.call may fail as args and kwargs properties may be None #2541

iwiwi opened this issue Jun 27, 2022 · 2 comments · May be fixed by #2545
Assignees

Comments

@iwiwi
Copy link

iwiwi commented Jun 27, 2022

  • Version: 5.29.2
  • Python: 3.10.4
  • OS: linux

What was wrong?

Depending on the way how a ContractFunction is instantiated, its args and kwargs may be None, which occurs errors when invoking call.

Example code

import json
from web3.auto.infura import w3

USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
EIP20_ABI = json.loads('[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_spender","type":"address"},{"indexed":false,"name":"_value","type":"uint256"}],"name":"Approval","type":"event"}]')

contract = w3.eth.contract(USDC, abi=EIP20_ABI)
f = contract.get_function_by_signature("decimals()")
f.call()

Result

Traceback (most recent call last):
  File "...", line 14, in <module>
    f.call()
  File ".../venv/lib/python3.10/site-packages/web3/contract.py", line 957, in call
    return call_contract_function(
TypeError: Value after * must be an iterable, not NoneType

How can it be fixed?

The minimal fix may be changing *self.args and **self.kwargs to *(self.args or []) and **(self.kwargs or {}) in the following lines:

web3.py/web3/contract.py

Lines 1222 to 1223 in c68f656

*self.args,
**self.kwargs,

I can work on creating a PR.

@kclowes
Copy link
Collaborator

kclowes commented Jun 27, 2022

Sure, a PR would be great. Thanks!

@iwiwi
Copy link
Author

iwiwi commented Jun 28, 2022

Thanks for your response! Created a PR: #2545

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants