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-9/

Smart Contract Deployment Service

Build a contract deployment service that can deploy Ethereum smart contracts to a blockchain network.

Requirements

Create a Python module that provides functionality to deploy smart contracts given their bytecode and ABI. The module should:

  1. Accept contract bytecode (as a hex string), contract ABI (as JSON), and constructor arguments
  2. Connect to an Ethereum node and deploy the contract
  3. Wait for the deployment transaction to be mined
  4. Return the deployed contract's address and deployment transaction hash
  5. Provide gas estimation before deployment
  6. Handle deployment errors gracefully

Implementation Details

Your solution should include:

  • A function estimate_deployment_gas(w3, bytecode, abi, constructor_args) that estimates the gas required for deployment
  • A function deploy_contract(w3, bytecode, abi, constructor_args, deployer_address) that deploys the contract and returns a dictionary with keys contract_address and tx_hash
  • Proper error handling for deployment failures
  • The deployment function should wait for the transaction receipt before returning

Test Cases { .test }

Create a test file test_deployment.py with the following test cases:

Test 1: Deploy Simple Storage Contract { @test }

Given:

  • A simple storage contract with bytecode: 0x608060405234801561001057600080fd5b5060405161012a38038061012a83398101604081905261002f91610037565b600055610050565b60006020828403121561004957600080fd5b5051919050565b60cd8061005e6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c80632e64cec11460375780636057361d146051575b600080fd5b603d6069565b6040519081526020015b60405180910390f35b6067605c366004608b565b600055565b005b60005481565b600080fd5b6000602082840312156099578081fd5b503591905056fea2646970667358221220f3e0a7a1b9c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e064736f6c63430008070033
  • ABI: [{"inputs":[{"internalType":"uint256","name":"initialValue","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"retrieve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"}]
  • Constructor argument: 42

Expected:

  • Gas estimation returns a positive integer
  • Deployment succeeds and returns a valid contract address (42-character hex string starting with '0x')
  • Transaction hash is returned (66-character hex string starting with '0x')

Test 2: Deploy Contract Without Constructor { @test }

Given:

  • A contract with no constructor arguments
  • Bytecode: 0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063ebb4a0af14602d575b600080fd5b60336045565b60405190815260200160405180910390f35b600a90509056fea264697066735822122033445566778899aabbccddeeff00112233445566778899aabbccddeeff00112264736f6c63430008070033
  • ABI: [{"inputs":[],"name":"getValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]
  • Constructor arguments: empty list

Expected:

  • Deployment succeeds with no constructor arguments
  • Returns valid contract address and transaction hash

Test 3: Handle Invalid Bytecode { @test }

Given:

  • Invalid bytecode: 0xinvalid
  • Valid ABI
  • Constructor arguments: []

Expected:

  • Function raises an appropriate exception or returns an error indication
  • Does not hang or crash

Dependencies { .dependencies }

web3 { .dependency }

Provides Ethereum blockchain interaction capabilities for contract deployment.

Notes

  • Use a local test network (e.g., Ganache, Hardhat node) or a test provider for testing
  • Ensure proper handling of transaction confirmation
  • The deployer address should have sufficient balance for deployment