or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

accounts.mdcli.mdcontracts.mdconversion-testing.mdindex.mdnetwork.mdproject.md
tile.json

tessl/pypi-eth-brownie

A Python framework for Ethereum smart contract deployment, testing and interaction.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/eth-brownie@1.21.x

To install, run

npx @tessl/cli install tessl/pypi-eth-brownie@1.21.0

index.mddocs/

eth-brownie

A comprehensive Python framework for Ethereum smart contract deployment, testing and interaction. Brownie provides publication-quality development tools for blockchain applications, serving as the foundational framework for Python-based Ethereum development with built-in support for Solidity and Vyper.

Package Information

  • Package Name: eth-brownie
  • Language: Python
  • Installation: pip install eth-brownie

Core Imports

import brownie
from brownie import accounts, Contract, project, network, chain, history, web3

Common imports for specific functionality:

from brownie.convert import Wei, Fixed, to_address
from brownie.test import given, strategy
from brownie.network import gas_limit, gas_price, connect, disconnect

Basic Usage

from brownie import accounts, Contract, project, network

# Connect to local development network
network.connect('development')

# Get account for transactions
account = accounts[0]  # Use first local account
# or load account from private key
account = accounts.add('0x...')  # Add account from private key

# Deploy a contract
contract_source = '''
pragma solidity ^0.8.0;
contract SimpleStorage {
    uint256 public storedData;
    function set(uint256 x) public { storedData = x; }
    function get() public view returns (uint256) { return storedData; }
}
'''

# Compile and deploy
compiled = project.compile_source(contract_source)
contract = compiled.SimpleStorage.deploy({'from': account})

# Interact with contract
tx = contract.set(42, {'from': account})
print(f"Transaction hash: {tx.txid}")
print(f"Stored value: {contract.get()}")

# Check transaction history
print(f"Gas used: {tx.gas_used}")
print(f"Transaction events: {tx.events}")

Architecture

Brownie's architecture centers on several key components:

  • Accounts: Manages private keys, signers, and transaction broadcasting
  • Network: Handles blockchain connections, RPC nodes, and network state
  • Project: Manages contract compilation, deployment artifacts, and scripts
  • Chain: Provides blockchain state management including snapshots and time control
  • Convert: Offers type conversion between Python and Ethereum data types

This design enables complete control over the smart contract development lifecycle from initial development through testing to production deployment.

Capabilities

Account Management

Comprehensive account management including local private key accounts, external signers, and transaction broadcasting with gas optimization and error handling.

class Accounts:
    def __getitem__(self, index: int) -> LocalAccount: ...
    def add(self, private_key: str) -> LocalAccount: ...
    def load(self, filename: str, password: str = None) -> LocalAccount: ...

class LocalAccount:
    def __init__(self, address: str, private_key: str): ...
    def transfer(self, to: str, amount: int, **kwargs) -> TransactionReceipt: ...
    def deploy(self, contract, *args, **kwargs) -> Contract: ...

Account Management

Contract Interaction

Smart contract deployment, method calls, event handling, and transaction management with comprehensive debugging and error reporting capabilities.

class Contract:
    def __init__(self, address: str, abi: list): ...
    def __getattr__(self, name: str): ...  # Contract method access
    
class ProjectContract(Contract):
    @classmethod
    def deploy(cls, *args, **kwargs) -> 'ProjectContract': ...
    
class ContractContainer:
    def deploy(self, *args, **kwargs) -> ProjectContract: ...
    def at(self, address: str) -> ProjectContract: ...

Contract Interaction

Network Management

Blockchain network connections, RPC node management, chain state control, and multi-network configuration for development, testing, and production environments.

def connect(network: str = None, launch_rpc: bool = True) -> None: ...
def disconnect() -> None: ...
def is_connected() -> bool: ...

class Chain:
    def snapshot() -> str: ...
    def revert(snapshot_id: str) -> None: ...
    def mine(blocks: int = 1) -> None: ...
    
class Rpc:
    def launch(self, cmd: str) -> None: ...
    def kill(self) -> None: ...

Network Management

Project Management

Brownie project creation, contract compilation, script execution, and build artifact management with support for both Solidity and Vyper smart contracts.

def new(path: str = ".", name: str = None, ignore_existing: bool = False) -> Project: ...
def load(project_path: str = ".", name: str = None) -> Project: ...
def compile_source(source: str, solc_version: str = None, **kwargs): ...
def run(script_path: str, method_name: str = None, *args, **kwargs): ...

class Project:
    def load_config(self) -> None: ...
    def compile(self, **kwargs) -> None: ...
    def close(self) -> None: ...

Project Management

Data Conversion & Testing

Type conversion utilities for seamless interaction between Python and Ethereum data types, plus integration with Hypothesis for property-based testing.

class Wei:
    def __init__(self, value: Union[int, str, float]): ...
    def to(self, unit: str) -> Union[int, float]: ...

def to_address(value: Any) -> str: ...
def to_uint(value: Any, type_str: str = "uint256") -> int: ...
def to_bytes(value: Any, type_str: str = "bytes32") -> bytes: ...

def given(**strategies) -> Callable: ...  # Testing decorator
def strategy(name: str, **kwargs) -> Callable: ...  # Strategy creator

Data Conversion & Testing

Command Line Interface

Comprehensive CLI tools for project management, compilation, testing, and deployment with support for interactive console and GUI.

brownie init [project_name]         # Initialize new project
brownie bake [template_name]        # Create from brownie-mix template
brownie compile [options]           # Compile contracts
brownie console [options]           # Interactive Python console
brownie test [options]              # Run test suite
brownie run [script] [method]       # Execute project scripts
brownie accounts [command]          # Manage local accounts
brownie networks [command]          # Manage network connections
brownie pm [command]                # Package manager
brownie gui [options]               # Launch web GUI

Command Line Interface

Exception Handling

Comprehensive exception hierarchy for handling network, contract, compilation, and transaction errors with detailed error messages and debugging support.

# Network Exceptions
class VirtualMachineError(Exception): ...  # EVM execution errors
class TransactionError(VirtualMachineError): ...  # Transaction failures
class RPCConnectionError(Exception): ...  # RPC connection issues
class MainnetUndefined(Exception): ...  # Mainnet configuration errors

# Project Exceptions  
class CompilerError(Exception): ...  # Contract compilation errors
class ProjectNotFound(Exception): ...  # Missing project errors
class ContractNotFound(Exception): ...  # Contract reference errors

# Account Exceptions
class UnknownAccount(Exception): ...  # Invalid account references

Exception Handling

Configuration Management

Global configuration system for network settings, compiler options, and development environment customization through brownie-config.yaml files.

# Global configuration access
config: ConfigContainer  # Configuration settings container

# Configuration categories
config.networks          # Network connection settings
config.compiler          # Solidity/Vyper compiler settings  
config.dependencies      # Package dependency management
config.hypothesis        # Property-based testing configuration

Global Objects

# Global singletons available after import
accounts: Accounts  # Account management
chain: Chain        # Blockchain state
history: TxHistory  # Transaction history  
rpc: Rpc           # RPC node control
web3: Web3         # Web3 interface
multicall: Multicall  # Batch calls
config: ConfigContainer  # Configuration

# Constants
ETH_ADDRESS: str = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
ZERO_ADDRESS: str = "0x0000000000000000000000000000000000000000"