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.
The main
module contains methods for conncting to or disconnecting from the network. All of these methods are available directly from brownie.network
.
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>
.
The alert
module is used to set up notifications and callbacks based on state changes in the blockchain.
Alerts and callbacks are handled by creating instances of the Alert
class.
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.
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 toContractContainer.deploy <ContractContainer.deploy>
. Because they are compiled and deployed directly by Brownie, they provide greater debugging capability.
These classes have identical APIs.
New Contract
objects are created with one of the following class methods.
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.
The gas
module contains gas strategy classes, as well as abstract base classes for buiding your own gas strategies.
Abstract base classes for building your own gas strategies.
To implement a simple gas strategy, subclass SimpleGasStrategy <brownie.network.gas.bases.SimpleGasStrategy>
and include the following method:
To implement a scaling strategy, subclass one of the above ABCs and implement the following generator function:
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.
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.
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.
The transaction
module contains the TransactionReceipt <brownie.network.transaction.TransactionReceipt>
class and related internal 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%)
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.
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.