A Python library for interacting with Ethereum blockchain
Overall
score
88%
Evaluation — 88%
↑ 1.01xAgent success when using this tile
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
Install with Tessl CLI
npx tessl i tessl/pypi-web3docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10