Interacting with smart contracts
You can only interact with a smart contract if it has public or external functions. The smart contract you’ve deployed has three external functions: store
, retrieve
, and donate
.
From the end user’s perspective, the function can be divided into reading functions and altering-state or writing functions. The smart contract has one reading function, retrieve
.
Let’s execute the retrieve
method. Create a file named execute_retrieve.py
and add the following code to it:
from web3 import Web3 with open("abi.json") as f: abi = f.read().strip() w3 = Web3(Web3.IPCProvider('/tmp/geth.ipc')) address = "0x8bb44f25E5b25ac14c8A9f5BFAcdFd1a700bA18B" contract = w3.eth.contract(address=address, abi=abi) number = contract.functions.retrieve().call() print(number)
Make sure you change the address of the smart contract in the script to your smart contract’s address. Also, change the...