Brownie API

brownie

The brownie package is the main package containing all of Brownie’s functionality.

>>> from brownie import *
>>> dir()
['Contract', 'Fixed', 'Wei', 'accounts', 'alert', 'compile_source', 'config', 'history', 'network', 'project', 'rpc', 'run', 'web3']

brownie.exceptions

The exceptions module contains all Brownie Exception and Warning classes.

Exceptions

exception brownie.exceptions.CompilerError

Raised by the compiler when there is an error within a contract’s source code.

exception brownie.exceptions.ContractExists

Raised when attempting to create a new Contract object, when one already exists for the given address.

exception brownie.exceptions.ContractNotFound

Raised when attempting to access a Contract object that no longer exists because the local network was reverted.

exception brownie.exceptions.EventLookupError

Raised during lookup errors by EventDict and _EventItem.

exception brownie.exceptions.IncompatibleEVMVersion

Raised when attempting to deploy a contract that was compiled to target an EVM version that is imcompatible than the currently active local RPC client.

exception brownie.exceptions.IncompatibleSolcVersion

Raised when a project requires a version of solc that is not installed or not supported by Brownie.

exception brownie.exceptions.InvalidManifest

Raised when attempting to process an improperly formatted ethPM package.

exception brownie.exceptions.MainnetUndefined

Raised when an action requires interacting with the main-net, but no "mainnet" network is defined.

exception brownie.exceptions.NamespaceCollision

Raised by Sources when the multiple source files contain a contract with the same name.

exception brownie.exceptions.PragmaError

Raised when a contract has no pragma directive, or a pragma which requires a version of solc that cannot be installed.

exception brownie.exceptions.ProjectAlreadyLoaded

Raised by project.load if a project has already been loaded.

exception brownie.exceptions.ProjectNotFound

Raised by project.load when a project cannot be found at the given path.

exception brownie.exceptions.UndeployedLibrary

Raised when attempting to deploy a contract that requires an unlinked library, but the library has not yet been deployed.

exception brownie.exceptions.UnknownAccount

Raised when the Accounts container cannot locate a specified Account object.

exception brownie.exceptions.UnsetENSName

Raised when an ENS name is unset (resolves to 0x00).

exception brownie.exceptions.UnsupportedLanguage

Raised when attempting to compile a language that Brownie does not support.

exception brownie.exceptions.RPCConnectionError

Raised when the RPC process is active and web3 is connected, but Brownie is unable to communicate with it.

exception brownie.exceptions.RPCProcessError

Raised when the RPC process fails to launch successfully.

exception brownie.exceptions.RPCRequestError

Raised when a direct request to the RPC client has failed, such as a snapshot or advancing the time.

exception brownie.exceptions.VirtualMachineError

Raised when a contract call causes the EVM to revert.

Warnings

exception brownie.exceptions.BrownieCompilerWarning

Raised by Contract.from_explorer when a contract cannot be compiled, or compiles successfully but produces unexpected bytecode.

exception brownie.exceptions.BrownieEnvironmentWarning

Raised on unexpected environment conditions.

exception brownie.exceptions.InvalidArgumentWarning

Raised on non-critical, invalid arguments passed to a method, function or config file.

brownie._config

The _config module handles all Brownie configuration settings. It is not designed to be accessed directly. If you wish to view or modify config settings while Brownie is running, import brownie.config which will return a ConfigDict with the active settings:

>>> from brownie import config
>>> type(config)
<class 'brownie._config.ConfigDict'>
>>> config['network_defaults']
{'name': 'development', 'gas_limit': False, 'gas_price': False}
class brownie._config.ConfigDict

Subclass of dict that prevents adding new keys when locked. Used to hold config file settings.

>>> from brownie.types import ConfigDict
>>> s = ConfigDict({'test': 123})
>>> s
{'test': 123}

ConfigDict Internal Methods

classmethod ConfigDict._lock()

Locks the ConfigDict. When locked, attempts to add a new key will raise a KeyError.

>>> s._lock()
>>> s['other'] = True
Traceback (most recent call last):
  File "<console>", line 1, in <module>
KeyError: 'other is not a known config setting'
classmethod ConfigDict._unlock()

Unlocks the ConfigDict. When unlocked, new keys can be added.

>>> s._unlock()
>>> s['other'] = True
>>> s
{'test': 123, 'other': True}
classmethod ConfigDict._copy()

Returns a copy of the object as a dict.

brownie._singleton

class brownie._singleton._Singleton

Internal metaclass used to create singleton objects. Instantiating a class derived from this metaclass will always return the same instance, regardless of how the child class was imported.