or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/web3@7.13.x
tile.json

tessl/pypi-web3

tessl install tessl/pypi-web3@7.13.0

A Python library for interacting with Ethereum blockchain

Agent Success

Agent success rate when using this tile

88%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.01x

Baseline

Agent success rate without this tile

87%

task.mdevals/scenario-7/

Token Transfer Gas Estimator

Build a utility that estimates the gas cost for ERC-20 token transfers and compares gas costs across different transfer amounts.

Overview

Create a Python module that connects to an Ethereum node and provides gas estimation functionality for ERC-20 token transfers. The module should estimate gas for different transfer scenarios and help users understand the gas requirements before executing transactions.

Capabilities

Connect to Ethereum network

  • Establishes connection to an Ethereum provider @test
  • Verifies connection is active and working @test

Estimate gas for token transfer

  • Given a token contract address, sender address, recipient address, and amount, estimates the gas required for a transfer @test
  • Returns estimated gas as an integer value @test

Compare gas costs for multiple amounts

  • Given a token contract and recipient, estimates gas for transferring multiple different amounts @test
  • Returns a dictionary mapping each amount to its estimated gas cost @test

Handle estimation errors

  • When estimating gas for a transfer that would fail (e.g., insufficient balance), raises an appropriate exception @test
  • When provided with an invalid contract address, raises an appropriate exception @test

Implementation

@generates

API

from web3 import Web3
from typing import Dict

class TokenGasEstimator:
    """
    Estimates gas costs for ERC-20 token transfers.
    """

    def __init__(self, provider_url: str):
        """
        Initialize the estimator with an Ethereum provider.

        Args:
            provider_url: URL of the Ethereum node (e.g., HTTP RPC endpoint)
        """
        pass

    def is_connected(self) -> bool:
        """
        Check if the connection to the Ethereum node is active.

        Returns:
            True if connected, False otherwise
        """
        pass

    def estimate_transfer_gas(
        self,
        token_address: str,
        from_address: str,
        to_address: str,
        amount: int
    ) -> int:
        """
        Estimate gas required for an ERC-20 token transfer.

        Args:
            token_address: Address of the ERC-20 token contract
            from_address: Address sending the tokens
            to_address: Address receiving the tokens
            amount: Amount of tokens to transfer (in smallest unit)

        Returns:
            Estimated gas units required for the transfer

        Raises:
            Exception: If estimation fails (e.g., insufficient balance, invalid contract)
        """
        pass

    def compare_transfer_costs(
        self,
        token_address: str,
        from_address: str,
        to_address: str,
        amounts: list[int]
    ) -> Dict[int, int]:
        """
        Compare gas costs for transferring different amounts.

        Args:
            token_address: Address of the ERC-20 token contract
            from_address: Address sending the tokens
            to_address: Address receiving the tokens
            amounts: List of different amounts to estimate

        Returns:
            Dictionary mapping each amount to its estimated gas cost

        Raises:
            Exception: If any estimation fails
        """
        pass

Dependencies { .dependencies }

web3 { .dependency }

Python library for interacting with Ethereum blockchain. Provides connection management, contract interaction, and gas estimation capabilities.

@satisfied-by