Smart Contracts
Last updated
import web3
import json
# endpoint, address, abi
PROVIDER_ENDPOINT = "https://eth-sepolia.g.alchemy.com/v2/..."
CONTRACT_ADDRESS = "0x..."
with open("<abi_file_path>.json") as f:
CONTRACT_ABI = json.load(f)
# web3 client
w3 = web3.Web3(web3.Web3.HTTPProvider(PROVIDER_ENDPOINT))
# example using BetML.sol contract
ml_ct = w3.eth.contract(address=CONTRACT_ADDRESS, abi=CONTRACT_ABI)
ml_filter_results = ml_ct.events.MLBetResult.create_filter(fromBlock='latest')
ml_bet_results = ml_filter_results.get_all_entries()
# print logs
for log in ml_bet_results:
print(log['args'], log['event'])/* BetConsumer.sol */
event RequestGameIdInit(bytes32 indexed requestId, uint256 game_id);/* BetConsumer.sol */
event RequestGameIdOdds(bytes32 indexed requestId, uint256 game_id);/* BetConsumer.sol */
event RequestGameIdResults(bytes32 indexed requestId, uint256 game_id);/* BetCore.sol */
event GameAdded(uint256 gameId, string league);