0

I have an assignment for which I must write a client that can interact with a deployed contract by transacting and filtering event logs, but I cannot figure out how to successfully get either to work through web3py. I have my contract compiled and deployed on Remix, but am not sure how to get the right provider or other setup to be able to properly interact with it from a python program. What I have tried so far is to set the WEB3_INFURA_PROJECT_ID variable to the project ID of an Infura project I started, then use web3.auto.infura's w3, and to use a WebsocketProvider with the URL given by Infura. (Note that w3.eth.accounts is an empty list)

I then get the contract using w3.eth.contract(abi = <Remix's produced ABI>)(<address of Remix contract>). In either case, if I try to do some transaction with contract.functions.<function name>(<params>).transact(), I receive

ValueError: {'code': -32601, 'message': 'The method eth_sendTransaction does not exist/is not available'}

I also want to be able to get all instances of a certain event in my contract that have occurred on the blockchain through this program. So, if I call a function through the Remix IDE that produces an event log, then try to filter it using

filter = contract.events.<event name>.createFilter(fromBlock='latest')
filter.get_new_entries()

I get an empty list. If I instead use filter.get_all_entries(), the same happens. It also doesn't appear to change if I first create the filter and then call the function in Remix, then call get_XXX_entries(). If instead, when creating the filter, I use kwargs fromBlock = 0, toBlock = 'latest', then get_new_entries() still returns an empty list, while get_all_entries() causes

concurrent.futures._base.TimeoutError

Basically, I want to know what I must do in order to test and develop this python program so that it can transact and retrieve event logs with this contract deployed over Remix. Is there a way to do this without actually having to buy/spend gas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.