web3.py 7¶
Not executed for this release
The standard-library opcode probe is the executed
Python example. Pin web3 when you test (e.g. pip install web3==7.6.0).
pq_w3_example.py
import json, os
from web3 import Web3
from eth_account import Account
w3 = Web3(Web3.HTTPProvider(os.environ.get("PQWERAI_RPC", "http://127.0.0.1:8545")))
assert w3.eth.chain_id == 77240, "not the PQWERAI testnet"
print("head", w3.eth.block_number)
acct = Account.from_key(Account.decrypt(json.load(open("keystore/dev")), open("keystore/dev.password").read().strip()))
tx = {"to": "0x000000000000000000000000000000000000dEaD", "value": w3.to_wei(0.01, "ether"),
"nonce": w3.eth.get_transaction_count(acct.address, "pending"), "chainId": 77240,
"maxPriorityFeePerGas": w3.eth.max_priority_fee, "type": 2}
tx["maxFeePerGas"] = 2 * w3.eth.get_block("latest")["baseFeePerGas"] + tx["maxPriorityFeePerGas"]
tx["gas"] = w3.eth.estimate_gas({**tx, "from": acct.address})
h = w3.eth.send_raw_transaction(acct.sign_transaction(tx).raw_transaction)
r = w3.eth.wait_for_transaction_receipt(h)
status = w3.provider.make_request("g4_status", [])["result"]
print("final" if status["finalized_height"] >= r["blockNumber"] else "awaiting finality")
Sources at 72057fe3ec: testnet/release/network/network.json · developers/examples/python/opcode_probe.py
Found a problem? Report a documentation issue · Build testnet-rc1+72057fe3ec