Here is an example using Brownie that should help:
import time
from brownie import Contract, network, web3
abi = {} # contract ABI as a dict
address = "0x00" # contract address as a string
network.connect('mainnet')
my_contract = Contract("MyContractName", address, abi=abi)
height = web3.eth.blockNumber
while True:
result = my_contract.myCallableFn(arg1, arg2) # change to call the desired method
if result == desired_result:
# do whatever you need to do
while web3.eth.blockNumber == height:
time.sleep(1)
height = web3.eth.blockNumber
You will have to modify some configuration settings to point at your own node, or set an infura API key in your environment variables.
The documentation on accessing contract methods might also be useful if my example is unclear.
Hope this helps.
The relevant piece of documentation is here
You'll need to get the contract ABI from somewhere, either by having it from when you deployed, or using a different tool. Once you have that, you can use web3.py to load it:
store_var_contract = w3.eth.contract(
address=address,
abi=contract_interface['abi'])
You can then call the function in the contract using the variable you assigned the contract. The example in the docs includes how to estimate the gas and more.
So, if you load your contract using the snippet above, and you want to call a function withdrawToken()
, you could then use something like:
tx_hash = store_var_contract.functions.withdrawToken(0x..., 50).transact()
receipt = w3.eth.waitForTransactionReceipt(tx_hash)
Where 0x...
is the address you wanted, and 50
is a random number I picked for the amount, and should be replaced by a number of your choice. (Unless you coincidentally wanted 50.)
I'm going out on a limb here, but I have a suspicion part of the issue may be that you've already deployed the contract, and don't have its ABI. A few quick solutions may include using the Solidity compiler to get the ABI (solc --abi YourContract.sol
if you already have it installed), or if you know where an identical contract is deployed on a test chain or mainnet, getting its ABI from etherscan.
Best Answer
So web3 interpret "wad" as "wei".
References:
https://www.thebalance.com/gwei-5194614
https://norman-lm-fung.medium.com/interact-with-cronos-single-usdc-lp-with-web3-py-1e14c62a0d9c