1

Hi I am trying to use web3.py to connect some python code to a solidity contract and I am getting an error -- Web3 instance has no eth member.

    w3 = Web3(EthereumTesterProvider())

contract_source_path = r'\tournament.sol'
compiled_sol = compile_source_file(contract_source_path)

contract_id, contract_interface = compiled_sol.popitem()

address = deploy_contract(w3, contract_interface)
print("Deployed {0} to: {1}\n".format(contract_id, address))

tournament_contract = w3.eth.contract(
    address = address,
    abi=contract_interface['abi']
)

I am not sure why this is happening as the w3 variable holds Web3(EthereumTesterProvider()) which should have an eth member object.

8
  • Did you import the newer EthereumTesterProvider or the legacy version? Have you tried using the automatic provider without EthereumTesterProvider? May 1, 2018 at 17:23
  • i did use the newer EthereumTestererProvider and i just tried using automatic provider by itself but that says w3 is not callable. May 1, 2018 at 18:11
  • how do you use w3 auto. would it look like... codetournament_contract = w3().eth.contract(...) this produces error: w3 is not callable May 1, 2018 at 18:39
  • 1
    even just this produces the same error codefrom web3 import Web3 w3 = Web3() w3.eth.contract() May 1, 2018 at 19:25
  • 1
    no i am not so that is a good idea. thanks for the help May 2, 2018 at 15:41

2 Answers 2

0

Why not just use Infura?

linkUrl = 'https://mainnet.infura.io/your_secret_code'
w3 = Web3(HTTPProvider(linkUrl))
from web3.middleware import geth_poa_middleware
# inject the poa compatibility middleware to the innermost layer
w3.middleware_stack.inject(geth_poa_middleware, layer=0)
print("w3.version.node: " + w3.version.node)
0

I ran into the same problem and as a beginner too, I am not 100% sure if I got it right. I guess you'd would have figured out after 7 months so I'm trying to get some help here.

So, just as far as how understood it is that those sub classes of Web3 class like personal, eth and so on are modules which will be attached to Web3 class in runtime so it will work fine after linking to the Etherium server provider. I ran into the same warnings using Visual Code and when I just run it directly on bash with

python app_name.py

and it works fine so far.

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.