Skip to content

Latest commit

 

History

History
2759 lines (1782 loc) · 109 KB

api-network.rst

File metadata and controls

2759 lines (1782 loc) · 109 KB

Network API

The network package holds classes for interacting with the Ethereum blockchain. This is the most extensive package within Brownie and contains the majority of the user-facing functionality.

brownie.network.main

The main module contains methods for conncting to or disconnecting from the network. All of these methods are available directly from brownie.network.

brownie.network.account

The account module holds classes for interacting with Ethereum accounts for which you control the private key.

Classes in this module are not meant to be instantiated directly. The Accounts <brownie.network.account.Accounts> container is available as accounts (or just a) and will create each Account <brownie.network.account.Account> automatically during initialization. Add more accounts using Accounts.add <Accounts.add>.

Accounts

Accounts Attributes

Accounts Methods

Accounts Internal Methods

Account

Account Attributes

Account Methods

LocalAccount

LocalAccount Attributes

LocalAccount Methods

PublicKeyAccount

brownie.network.alert

The alert module is used to set up notifications and callbacks based on state changes in the blockchain.

Alert

Alerts and callbacks are handled by creating instances of the Alert class.

Module Methods

brownie.network.contract

The contract module contains classes for deploying and interacting with smart contracts.

When a project is loaded, Brownie automatically creates ContractContainer <brownie.network.contract.ContractContainer> instances from on the files in the contracts/ folder. New ProjectContract <brownie.network.contract.ProjectContract> instances are created via methods in the container.

If you wish to interact with a contract outside of a project where only the ABI is available, use the Contract <brownie.network.contract.Contract> class.

Arguments supplied to calls or transaction methods are converted using the methods outlined in the convert<api-convert> module.

Note

On networks where persistence is enabled, ProjectContract <brownie.network.contract.ProjectContract> instances will remain between sessions. Use ContractContainer.remove <ContractContainer.remove> to delete these objects when they are no longer needed. See the documentation on persistence<persistence> for more information.

ContractContainer

ContractContainer Attributes

ContractContainer Methods

ContractContainer Internal Methods

Contract and ProjectContract

Contract <brownie.network.contract.Contract> and ProjectContract <brownie.network.contract.ProjectContract> are both used to call or send transactions to smart contracts.

  • Contract <brownie.network.contract.Contract> objects are instantiated directly. They are used for interaction with already-deployed contracts that exist outside of a project.
  • ProjectContract <brownie.network.contract.ProjectContract> objects are created by calls to ContractContainer.deploy <ContractContainer.deploy>. Because they are compiled and deployed directly by Brownie, they provide greater debugging capability.

These classes have identical APIs.

Contract Classmethods

New Contract objects are created with one of the following class methods.

Contract Attributes

Contract Methods

Contract Internal Attributes

ContractCall

ContractCall Attributes

ContractCall Methods

ContractTx

ContractTx Attributes

ContractTx Methods

OverloadedMethod

InterfaceContainer

InterfaceConstructor

InterfaceConstructor Attributes

brownie.network.event

The event module contains classes and methods related to decoding transaction event logs. It is largely a wrapper around eth-event.

Brownie stores encrypted event topics in brownie/data/topics.json. The JSON file is loaded when this module is imported.

EventDict

Internal Classes and Methods

_EventItem

Internal Methods

brownie.network.gas

The gas module contains gas strategy classes, as well as abstract base classes for buiding your own gas strategies.

Gas Strategies

Gas Strategy ABCs

Abstract base classes for building your own gas strategies.

Simple Strategies

Simple Strategy Abstract Methods

To implement a simple gas strategy, subclass SimpleGasStrategy <brownie.network.gas.bases.SimpleGasStrategy> and include the following method:

Scaling Strategies

Scaling Strategy Abstract Methods

To implement a scaling strategy, subclass one of the above ABCs and implement the following generator function:

brownie.network.state

The state module contains classes to record transactions and contracts as they occur on the blockchain.

Classes in state are not meant to be instantiated directly. TxHistory <brownie.network.state.TxHistory> and Chain <brownie.network.state.Chain> objects are available as history and chain in the console and as pytest fixtures.

TxHistory

TxHistory Attributes

TxHistory Methods

TxHistory Internal Methods

Chain

Chain Attributes

Chain Methods

Internal Methods

The internal methods in the state module are used for tracking and adjusting the contents of various container objects when the local RPC network is reverted or reset.

brownie.network.rpc

The rpc module contains the Rpc <brownie.network.rpc.Rpc> class, which is used to interact with ganache-cli when running a local RPC environment.

Note

Account balances, contract containers and transaction history are automatically modified when the local RPC is terminated, reset or reverted.

Rpc

Rpc Methods

brownie.network.transaction

The transaction module contains the TransactionReceipt <brownie.network.transaction.TransactionReceipt> class and related internal methods.

TransactionReceipt

TransactionReceipt Attributes

TransactionReceipt Methods

>>> tx
<Transaction '0x830b842e24efae712b67dddd97633356122c36e6cf2193fcf9f7dc635c4cbe2f'>
>>> tx.wait(2)
This transaction already has 3 confirmations.
>>> tx.wait(6)
Required confirmations: 6/6
  Transaction confirmed - Block: 17   Gas used: 21000 (0.31%)

brownie.network.web3

The web3 module contains a slightly modified version of the web3.py Web3 <web3.Web3> class that is used throughout various Brownie modules for RPC communication.

Web3

See the Web3 API documentation for detailed information on all the methods and attributes available here. This document only outlines methods that differ from the normal Web3 <web3.Web3> public interface.

Web3 Methods

Web3 Attributes

Web3 Internals

Internal Methods