skills/blockchain/web3-py/SKILL.md
Python library for interacting with Ethereum blockchain via Web3 protocols.
npx skillsauth add alphaonedev/openclaw-graph web3-pyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
web3-py is a Python library for interacting with the Ethereum blockchain using Web3 protocols. It enables programmatic access to blockchain data, smart contracts, and transactions.
Use this skill when building Python applications that need to query Ethereum data, deploy smart contracts, or handle transactions. Applicable for dApps, blockchain analytics, or automated scripts interacting with Ethereum nodes.
Always import web3-py and initialize a Web3 instance with a provider. Use environment variables for sensitive keys, e.g., set INFURA_API_KEY in your shell. Structure code to handle asynchronous operations with web3.async for better performance. For production, wrap calls in try-except blocks and use a reliable provider URL.
web3.eth.get_balance(address). Example:
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/' + os.getenv('INFURA_API_KEY')))
balance = w3.eth.get_balance('0xYourAddress')
w3.eth.send_transaction(transaction). Example:
tx = {'from': account.address, 'to': '0xRecipient', 'value': w3.to_wei(1, 'ether')}
signed_tx = w3.eth.account.sign_transaction(tx, private_key=os.getenv('ETH_PRIVATE_KEY'))
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
contract.functions.myFunction().call(). Example:
contract = w3.eth.contract(address='0xContractAddress', abi=contract_abi)
result = contract.functions.balanceOf('0xAddress').call()
w3.eth.estimate_gas(transaction). Pass a dictionary with 'from', 'to', and 'data' keys.Integrate web3-py by installing via pip install web3. Configure providers with URLs like https://mainnet.infura.io/v3/$INFURA_API_KEY for Infura. Use env vars for keys: e.g., os.getenv('INFURA_API_KEY') for API access. For local nodes, use IPC: Web3(Web3.IPCProvider('/path/to/geth.ipc')). Ensure compatibility with Ethereum versions; specify chain ID in transactions to prevent replay attacks. Test integrations in a sandbox like Ganache before production.
Handle connection errors with try-except for ConnectionError, e.g.:
try:
w3.eth.get_block('latest')
except web3.exceptions.ConnectionError:
print("Node unreachable; check provider URL and network status.")
For transaction failures, catch ValueError for insufficient funds or gas issues:
try:
tx_hash = w3.eth.send_transaction(tx)
except ValueError as e:
if 'insufficient funds' in str(e):
raise Exception("Add funds to account before retrying.")
Validate inputs like addresses with w3.is_address(address) before use. Log errors with details like error codes (e.g., RPC errors from providers) for debugging.
INFURA_API_KEY env var, then run the snippet above under Common Commands/API for contract calls.w3.eth.contract to deploy. Example: In code, create a contract instance and send a transaction with the bytecode, handling gas limits as shown in the send_transaction example.tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui