Connect an ARIA Python tool to a deployed Solidity contract on Sepolia via web3.py
Connect Python tool to contract: $ARGUMENTS
Read the Solidity contract in ARIA/contracts/ — function signatures, parameters, return types, events, access control.
Read the Python tool in ARIA/agent/tools/ that will call this contract.
Read ARIA/agent/config.py for the contract address field. If missing, add it to Web3Config and ARIA/.env.example.
Implement in the tool file:
a. Define minimal ABI (module-level constant, only needed functions):
_CONTRACT_ABI: list[dict] = [
{
"type": "function",
"name": "functionName",
"inputs": [{"name": "param", "type": "uint256"}],
"outputs": [{"name": "", "type": "uint8"}],
"stateMutability": "view",
},
]
b. For read-only (view) calls:
from web3 import Web3
w3 = Web3(Web3.HTTPProvider(config.web3.sepolia_rpc_url))
contract = w3.eth.contract(
address=Web3.to_checksum_address(config.web3.<address_field>),
abi=_CONTRACT_ABI,
)
result = contract.functions.functionName(arg1).call()
c. For state-changing (write) calls:
account = w3.eth.account.from_key(config.web3.agent_private_key)
tx = contract.functions.functionName(arg1).build_transaction({
"from": account.address,
"nonce": w3.eth.get_transaction_count(account.address),
"gas": 200000,
"gasPrice": w3.eth.gas_price,
"chainId": 11155111, # Sepolia
})
signed = account.sign_transaction(tx)
tx_hash = w3.eth.send_raw_transaction(signed.raw_transaction)
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
Add span attributes: contract address, function name, tx_hash, gas_used.
Handle errors: ContractLogicError (revert), TransactionNotFound, connection errors.
Always use Web3.to_checksum_address() for addresses. Sepolia chain ID: 11155111.