CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-web3

A Python library for interacting with Ethereum blockchain

Overall
score

88%

Evaluation88%

1.01x

Agent success when using this tile

Overview
Eval results
Files

ethereum-operations.mddocs/

Ethereum Operations

Core Ethereum blockchain operations including transaction management, block and account queries, smart contract deployment and interaction, event filtering, and gas management.

Capabilities

Account Operations

Account management and balance queries.

class Eth:
    @property
    def accounts(self) -> List[ChecksumAddress]:
        """Get list of available accounts."""

    @property
    def coinbase(self) -> ChecksumAddress:
        """Get coinbase account."""

    def get_balance(
        self,
        account: AnyAddress,
        block_identifier: BlockIdentifier = "latest"
    ) -> Wei:
        """
        Get account balance in Wei.
        
        Parameters:
        - account: Account address
        - block_identifier: Block number, hash, or 'latest'/'pending'
        """

    def get_transaction_count(
        self,
        account: AnyAddress,
        block_identifier: BlockIdentifier = "latest"
    ) -> Nonce:
        """
        Get account transaction count (nonce).
        
        Parameters:
        - account: Account address
        - block_identifier: Block number, hash, or 'latest'/'pending'
        """

    def get_code(
        self,
        account: AnyAddress,
        block_identifier: BlockIdentifier = "latest"
    ) -> HexBytes:
        """
        Get account code (for contracts).
        
        Parameters:
        - account: Account address
        - block_identifier: Block number, hash, or 'latest'/'pending'
        """

Block Operations

Block queries and information retrieval.

class Eth:
    @property
    def block_number(self) -> BlockNumber:
        """Get latest block number."""

    def get_block(
        self,
        block_identifier: BlockIdentifier,
        full_transactions: bool = False
    ) -> BlockData:
        """
        Get block data.
        
        Parameters:
        - block_identifier: Block number, hash, or 'latest'/'pending'
        - full_transactions: Include full transaction data
        """

    def get_block_transaction_count(
        self,
        block_identifier: BlockIdentifier
    ) -> int:
        """
        Get transaction count in block.
        
        Parameters:
        - block_identifier: Block number, hash, or 'latest'/'pending'
        """

    def get_block_receipts(
        self,
        block_identifier: BlockIdentifier
    ) -> BlockReceipts:
        """
        Get all transaction receipts in block.
        
        Parameters:
        - block_identifier: Block number, hash, or 'latest'/'pending'
        """

    @property
    def gas_price(self) -> Wei:
        """Get current gas price."""

    @property
    def max_priority_fee(self) -> Wei:
        """Get max priority fee per gas."""

    @property
    def blob_base_fee(self) -> Wei:
        """Get current blob base fee."""

    def fee_history(
        self,
        block_count: int,
        newest_block: BlockIdentifier = "latest",
        reward_percentiles: Optional[List[float]] = None
    ) -> FeeHistory:
        """
        Get fee history data.
        
        Parameters:
        - block_count: Number of blocks to query
        - newest_block: Most recent block
        - reward_percentiles: Percentiles for reward calculation
        """

Transaction Operations

Transaction creation, sending, and monitoring.

class Eth:
    def send_transaction(self, transaction: TxParams) -> HexBytes:
        """
        Send transaction.
        
        Parameters:
        - transaction: Transaction parameters
        
        Returns:
        Transaction hash
        """

    def send_raw_transaction(self, transaction: HexStr) -> HexBytes:
        """
        Send raw signed transaction.
        
        Parameters:
        - transaction: Signed transaction data
        
        Returns:
        Transaction hash
        """

    def get_transaction(self, transaction_hash: Hash32) -> TxData:
        """
        Get transaction data.
        
        Parameters:
        - transaction_hash: Transaction hash
        """

    def get_transaction_receipt(self, transaction_hash: Hash32) -> TxReceipt:
        """
        Get transaction receipt.
        
        Parameters:
        - transaction_hash: Transaction hash
        """

    def get_raw_transaction(self, transaction_hash: Hash32) -> HexBytes:
        """
        Get raw transaction data.
        
        Parameters:
        - transaction_hash: Transaction hash
        """

    def get_transaction_by_block(
        self,
        block_identifier: BlockIdentifier,
        index: int
    ) -> TxData:
        """
        Get transaction by block and index.
        
        Parameters:
        - block_identifier: Block number, hash, or 'latest'/'pending'
        - index: Transaction index in block
        """

    def get_raw_transaction_by_block(
        self,
        block_identifier: BlockIdentifier,
        index: int
    ) -> HexBytes:
        """
        Get raw transaction by block and index.
        
        Parameters:
        - block_identifier: Block number, hash, or 'latest'/'pending'
        - index: Transaction index in block
        """

    def wait_for_transaction_receipt(
        self,
        transaction_hash: Hash32,
        timeout: float = 120,
        poll_latency: float = 0.1
    ) -> TxReceipt:
        """
        Wait for transaction to be mined.
        
        Parameters:
        - transaction_hash: Transaction hash
        - timeout: Maximum wait time in seconds
        - poll_latency: Polling interval in seconds
        """

    def estimate_gas(
        self,
        transaction: TxParams,
        block_identifier: BlockIdentifier = "latest"
    ) -> int:
        """
        Estimate gas for transaction.
        
        Parameters:
        - transaction: Transaction parameters
        - block_identifier: Block for estimation
        """

    def call(
        self,
        transaction: TxParams,
        block_identifier: BlockIdentifier = "latest",
        state_override: Optional[StateOverride] = None,
        ccip_read_enabled: Optional[bool] = None
    ) -> HexBytes:
        """
        Execute contract call without creating transaction.
        
        Parameters:
        - transaction: Transaction parameters
        - block_identifier: Block for execution
        - state_override: State override for the call
        - ccip_read_enabled: Enable CCIP read functionality
        """

    def create_access_list(
        self,
        transaction: TxParams,
        block_identifier: BlockIdentifier = "latest"
    ) -> CreateAccessListResponse:
        """
        Create access list for transaction.
        
        Parameters:
        - transaction: Transaction parameters
        - block_identifier: Block for estimation
        """

    def replace_transaction(
        self,
        transaction_hash: Hash32,
        new_transaction: TxParams
    ) -> HexBytes:
        """
        Replace pending transaction.
        
        Parameters:
        - transaction_hash: Original transaction hash
        - new_transaction: New transaction parameters
        """

    def modify_transaction(
        self,
        transaction_hash: Hash32,
        **transaction_params: Any
    ) -> HexBytes:
        """
        Modify pending transaction.
        
        Parameters:
        - transaction_hash: Original transaction hash
        - transaction_params: Modified transaction parameters
        """

Contract Operations

Smart contract deployment and interaction.

class Eth:  
    def contract(
        self,
        address: Optional[AnyAddress] = None,
        abi: Optional[ABI] = None,
        ContractFactoryClass: Type[Contract] = Contract,
        **contract_kwargs: Any
    ) -> Contract:
        """
        Create contract instance.
        
        Parameters:
        - address: Contract address (for existing contracts)
        - abi: Contract ABI
        - ContractFactoryClass: Contract factory class
        - contract_kwargs: Additional contract arguments
        """

    def get_storage_at(
        self,
        account: AnyAddress,
        position: int,
        block_identifier: BlockIdentifier = "latest"
    ) -> HexBytes:
        """
        Get storage at position.
        
        Parameters:
        - account: Contract address
        - position: Storage slot position  
        - block_identifier: Block number, hash, or 'latest'/'pending'
        """

    def get_proof(
        self,
        account: AnyAddress,
        positions: Sequence[int],
        block_identifier: BlockIdentifier = "latest"
    ) -> MerkleProof:
        """
        Get Merkle proof for account and storage positions.
        
        Parameters:
        - account: Account address
        - positions: Storage positions to prove
        - block_identifier: Block number, hash, or 'latest'/'pending'
        """

    def set_contract_factory(
        self,
        contract_factory: Type[Contract]
    ) -> None:
        """
        Set contract factory class.
        
        Parameters:
        - contract_factory: Contract factory class
        """

Signing Operations

Cryptographic signing operations for transactions and messages.

class Eth:
    def sign(
        self,
        account: AnyAddress,
        data: Union[int, bytes] = None,
        hexstr: HexStr = None,
        text: str = None
    ) -> HexStr:
        """
        Sign data with account.
        
        Parameters:
        - account: Account address
        - data: Data to sign (bytes)
        - hexstr: Data to sign (hex string)
        - text: Data to sign (text)
        """

    def sign_transaction(self, transaction: TxParams) -> SignedTx:
        """
        Sign transaction.
        
        Parameters:
        - transaction: Transaction parameters
        """

    def sign_typed_data(
        self,
        account: AnyAddress,
        data: Dict[str, Any]
    ) -> HexStr:
        """
        Sign structured data (EIP-712).
        
        Parameters:
        - account: Account address
        - data: Structured data to sign
        """

Simulation Operations

Advanced transaction simulation capabilities.

class Eth:
    def simulate_v1(
        self,
        payload: SimulateV1Payload,
        block_identifier: BlockIdentifier
    ) -> Sequence[SimulateV1Result]:
        """
        Simulate transaction bundle.
        
        Parameters:
        - payload: Simulation payload
        - block_identifier: Block for simulation
        """

Event and Log Operations

Event filtering and log retrieval.

class Eth:
    def get_logs(self, filter_params: FilterParams) -> List[LogReceipt]:
        """
        Get logs matching filter.
        
        Parameters:
        - filter_params: Filter parameters
        """

    def filter(self, filter_params: FilterParams) -> LogFilter:
        """
        Create log filter.
        
        Parameters:  
        - filter_params: Filter parameters
        """

    def get_filter_changes(self, filter_id: HexStr) -> List[LogReceipt]:
        """
        Get filter changes.
        
        Parameters:
        - filter_id: Filter identifier
        """

    def get_filter_logs(self, filter_id: HexStr) -> List[LogReceipt]:
        """
        Get all logs for filter.
        
        Parameters:
        - filter_id: Filter identifier
        """

    def uninstall_filter(self, filter_id: HexStr) -> bool:
        """
        Uninstall filter.
        
        Parameters:
        - filter_id: Filter identifier
        """

Mining Operations

Mining and blockchain state operations.

class Eth:
    @property
    def mining(self) -> bool:
        """Check if node is mining."""

    @property
    def hashrate(self) -> int:
        """Get current hashrate."""

    @property
    def syncing(self) -> Union[bool, SyncStatus]:
        """Get syncing status."""

    @property
    def chain_id(self) -> int:
        """Get chain ID."""

Async Operations

All Eth operations have async equivalents in AsyncEth with the same API.

class AsyncEth:
    async def get_balance(
        self,
        account: AnyAddress,
        block_identifier: BlockIdentifier = "latest"
    ) -> Wei:
        """Async version of get_balance."""

    async def send_transaction(self, transaction: TxParams) -> HexBytes:
        """Async version of send_transaction."""

    async def wait_for_transaction_receipt(
        self,
        transaction_hash: Hash32,
        timeout: float = 120,
        poll_latency: float = 0.1
    ) -> TxReceipt:
        """Async version of wait_for_transaction_receipt."""

    async def subscribe(
        self,
        subscription_type: SubscriptionType,
        subscription_arg: Optional[Union[LogsSubscriptionArg, bool]] = None,
        handler: Optional[EthSubscriptionHandler] = None,
        handler_context: Optional[Dict[str, Any]] = None,
        label: Optional[str] = None,
        parallelize: Optional[bool] = None
    ) -> HexStr:
        """
        Subscribe to events (WebSocket only).
        
        Parameters:
        - subscription_type: Type of subscription
        - subscription_arg: Subscription arguments
        - handler: Event handler function
        - handler_context: Handler context
        - label: Subscription label
        - parallelize: Enable parallel processing
        """

    async def unsubscribe(self, subscription_id: HexStr) -> bool:
        """
        Unsubscribe from events.
        
        Parameters:
        - subscription_id: Subscription ID to cancel
        """

Usage Examples

Basic Account Operations

from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR-PROJECT-ID'))

# Get account balance
address = '0x742d35Cc6635C0532925a3b8D5c0d9E3C4B3c8'
balance = w3.eth.get_balance(address)
balance_ether = w3.from_wei(balance, 'ether')
print(f"Balance: {balance_ether} ETH")

# Get transaction nonce
nonce = w3.eth.get_nonce(address)
print(f"Nonce: {nonce}")

Transaction Sending

from web3 import Web3

w3 = Web3(Web3.HTTPProvider('http://localhost:8545'))

# Build transaction
transaction = {
    'from': '0x742d35Cc6635C0532925a3b8D5c0d9E3C4B3c8',
    'to': '0x123...',
    'value': w3.to_wei(1, 'ether'),
    'gas': 21000,
    'gasPrice': w3.to_wei(20, 'gwei'),
    'nonce': w3.eth.get_nonce('0x742d35Cc6635C0532925a3b8D5c0d9E3C4B3c8')
}

# Send transaction
tx_hash = w3.eth.send_transaction(transaction)
print(f"Transaction hash: {tx_hash.hex()}")

# Wait for confirmation
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Transaction mined in block: {receipt.blockNumber}")

Block Queries

from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR-PROJECT-ID'))

# Get latest block
latest_block = w3.eth.get_block('latest')
print(f"Block number: {latest_block.number}")
print(f"Block hash: {latest_block.hash.hex()}")
print(f"Transaction count: {len(latest_block.transactions)}")

# Get specific block with full transactions
block = w3.eth.get_block(17000000, full_transactions=True)
for tx in block.transactions:
    print(f"TX: {tx.hash.hex()} from {tx['from']} to {tx.to}")

Event Filtering

from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR-PROJECT-ID'))

# Filter for Transfer events
filter_params = {
    'fromBlock': 'latest',
    'toBlock': 'latest',
    'topics': ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef']
}

# Create filter
event_filter = w3.eth.filter(filter_params)

# Get filter changes
while True:
    for event in w3.eth.get_filter_changes(event_filter.filter_id):
        print(f"Transfer event: {event}")
    time.sleep(2)

Async Operations

import asyncio
from web3 import AsyncWeb3

async def main():
    w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider('https://mainnet.infura.io/v3/YOUR-PROJECT-ID'))
    
    # Get balance asynchronously
    balance = await w3.eth.get_balance('0x742d35Cc6635C0532925a3b8D5c0d9E3C4B3c8')
    print(f"Balance: {w3.from_wei(balance, 'ether')} ETH")
    
    # Get latest block
    block = await w3.eth.get_block('latest')
    print(f"Latest block: {block.number}")

asyncio.run(main())

Install with Tessl CLI

npx tessl i tessl/pypi-web3

docs

account-management.md

ens-operations.md

ethereum-operations.md

index.md

middleware.md

providers.md

smart-contracts.md

utilities.md

web3-client.md

tile.json