1

Testing this python code on UBUNTU :

import requests
import json
from eth_account import Account
from web3 import Web3, HTTPProvider
 
caller = "0xb9****f832860DBD"
private_key = "1d7bb4b13a48b54********5336726f"
 
url = 'https://sepolia.infura.io/v3/8afa5e30c******14b5d'
 
w3 = Web3(HTTPProvider(url))
#nonce = w3.eth.getTransactionCount(caller)
 
abi= '[{"constant": false,"inputs": [{"***************************": [{"name": "","type": "bool"}],"payable": false,"stateMutability": "view","type": "function"},{"constant": true,"inputs": [],"name": "Owner","outputs": [{"name": "","type": "address"}],"payable": false,"stateMutability": "view","type": "function"}]'
  
nonce=w3.eth.get_transaction_count(caller)
chainId = w3.eth.chain_id
 
contract_address = "0x*******9B78"
 
contract = w3.eth.contract(address=contract_address, abi=abi)

result = contract.functions.CheckMoneyOnTheContract({"chainId": chainId, "from": caller, "nonce": nonce })

 

When I try to continue my editor doesn'found contract.functions .....

Trace expl 1

web3.exceptions.Web3ValidationError: Could not identify the intended function with name CheckMoneyOnTheContract, positional arguments with type(s) dict and keyword arguments with type(s) {}. Found 1 function(s) with the name CheckMoneyOnTheContract: ['CheckMoneyOnTheContract()'] Function invocation failed due to improper number of arguments. has context menu

(For me the abi is correct)

Trace expl 2

Web3 version: Traceback (most recent call last): File "/home/**************epolia.py", line 7, in print(Web3.version) AttributeError: type object 'Web3' has no attribute 'version'

ABI portion:

{ "constant": true, "inputs": [], "name": "CheckMoneyOnTheContract", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" }

Can somebody tell me my ??

7
  • Which version of web3.py are you using ? Commented Apr 22 at 17:33
  • In the editor, it usually doesn't find and recommend the available functions in the instance. However, when you execute it, it would work if you're calling an existing function in the ABI. Commented Apr 22 at 17:38
  • web3.version -> not found .... more and more strange .... Commented Apr 22 at 21:54
  • Please edit the question and include the full Python traceback in the question Commented Apr 22 at 22:35
  • Trace included ... Thanks for your time. Commented Apr 22 at 23:05

1 Answer 1

0

I managed to fix the problem. The issue came mainly from the fact that the required number of arguments were not send to the smart contract function.

My editor still doesn't found contract.functions .... but is not an issue, it works.

Still doesn't know how to print the Web3 library version ....

Below is an example of a working example using one smart contract function with one string parameter.

param_value = "TestHash"  

transaction = {
    'to': contract_address,
    'from': caller,
    'gas': 200000, 
    'gasPrice': w3.to_wei('50', 'gwei'),  
    'nonce': w3.eth.get_transaction_count(caller), 
    'data': contract.encodeABI(fn_name='setHash', args=[param_value]),  
}
 
signed_txn = w3.eth.account.sign_transaction(transaction, private_key)
 
tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
 
w3.eth.wait_for_transaction_receipt(tx_hash) 
4
  • You can see the version installed with web3.__version__.
    – pacrob
    Commented Apr 23 at 13:13
  • In the python code ? like : print(web3.__version__) Commented Apr 23 at 14:48
  • On my side it's not working : No attribute 'version' Commented Apr 23 at 14:57
  • That's working for me with the current stable version 6.17.2. I'm not sure at what point it was added. ``` >>> import web3 >>> print(web3.__version__) 6.17.2 ```
    – pacrob
    Commented Apr 24 at 13:51

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.