tessl install tessl/pypi-web3@7.13.0A 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%
Build a utility that estimates the gas cost for ERC-20 token transfers and compares gas costs across different transfer amounts.
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.
@generates
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
"""
passPython library for interacting with Ethereum blockchain. Provides connection management, contract interaction, and gas estimation capabilities.
@satisfied-by