---
title: Python Brownie
slug: python-brownie
docTags: 
createdAt: 2022-07-21T09:16:38.000Z
---

Brownie is a Python-based development and testing framework for smart contracts targeting the [Ethereum Virtual Machine](https://solidity.readthedocs.io/en/v0.6.0/introduction-to-smart-contracts.html#the-ethereum-virtual-machine).

*Brownie requires the Ganache local test blockchain to be installed first. Else it will not work.*

**

To install Ganache you must install it globally using npm install -g.

```shell
npm install -g ganache
```

*&#xA;*
Installing Brownie[](https://eth-brownie.readthedocs.io/en/stable/install.html#installing-brownie)
--------------------------------------------------------------------------------------------------

The recommended way to install Brownie is via [pipx](https://github.com/pipxproject/pipx). Pipx is a tool to help you install and run end-user applications written in Python. It’s roughly similar to macOS’s brew, JavaScript’s npx, and Linux’s apt.

Pipx installs Brownie into a virtual environment and makes it available directly from the commandline. Once installed, you will never have to activate a virtual environment prior to using Brownie.

Pipx does not ship with Python. If you have not used it before you will probably need to install it.

To install pipx:

```shell
python3 -m pip install --user pipx
python3 -m pipx ensurepath
```


To install Brownie using pipx:

```shell
pipx install eth-brownie

```

Once installation is complete, type **brownie&#xA0;**&#x74;o verify that it worked:

```shell
$ brownie
Brownie - Python development framework for Ethereum

Usage:  brownie <command> [<args>...] [options <args>]
```

Type **brownie networks list** to view a list of existing networks.

## Add Caduceus To Brownie:[](https://eth-brownie.readthedocs.io/en/v1.14.5/network-management.html#adding-a-new-network)

To add a new network:

```shell
$ brownie networks add caduceus galaxytest  host='https://galaxy.block.caduceus.foundation' 
```

When declaring a new network, the following fields must always be included:

**environment:** the category that the network should be placed in, e.g. “Ethereum”, “Ethereum Classic”, or “Development”
**id**: a unique identifier for the network, e.g. “mainnet”
**host**: the address of the node to connect e.g. https\://galaxy.block.caduceus.foundation
The following fields are optional:

**name**: A longer name to use for the network. If not given, id is used.
**timeout**: The number of seconds to wait for a response when making an RPC call. Defaults to 30.



Creating a new project



To create a new project, create a new folder. Inside the new folder, type:

```shell
$ brownie init

```

Every Brownie project includes the following sub folders:

**contracts/:** Contract sources
**interfaces/:** Interface sources
**scripts/:&#x20;**&#x53;cripts for deployment and interaction
**tests/:** Scripts for testing the project
The following folders are also created, and used internally by Brownie for managing the project. You should not edit or delete files within these folders.
**build/:** Project data such as compiler artifacts and unit test results
reports/: JSON report files for use in the GUI



## Writing code for Caduceus EVM

The contracts folder holds all contract source files for the project. Each time Brownie is run, it checks for new or modified files within this folder. If any are found, they are compiled and included within the project.

Contracts may be written in Solidity (with a .sol extension) or Vyper (with a .vy extension).

We recommend Solidity due to the wider support base available.

You can write contracts and any dependencies inside the contracts folder.

## Working with Accounts[](https://eth-brownie.readthedocs.io/en/stable/core-accounts.html#working-with-accounts)

The [Accounts](https://eth-brownie.readthedocs.io/en/stable/api-network.html#brownie.network.account.Accounts) container (available as accounts or just a) allows you to access all your local accounts.

```javascript
>>> accounts
['0xC0BcE0346d4d93e30008A1FE83a2Cf8CfB9Ed301', '0xf414d65808f5f59aE156E51B97f98094888e7d92', '0x055f1c2c9334a4e57ACF2C4d7ff95d03CA7d6741', '0x1B63B4495934bC1D6Cb827f7a9835d316cdBB332', '0x303E8684b9992CdFA6e9C423e92989056b6FC04b', '0x5eC14fDc4b52dE45837B7EC8016944f75fF42209', '0x22162F0D8Fd490Bde6Ffc9425472941a1a59348a', '0x1DA0dcC27950F6070c07F71d1dE881c3C67CEAab', '0xa4c7f832254eE658E650855f1b529b2d01C92359','0x275CAe3b8761CEdc5b265F3241d07d2fEc51C0d8']
>>> accounts[0]
<Account object '0xC0BcE0346d4d93e30008A1FE83a2Cf8CfB9Ed301'>
```

Each individual account is represented by an [Account](https://eth-brownie.readthedocs.io/en/stable/api-network.html#brownie.network.account.Account) object that can perform actions such as querying a balance or sending ETH.



The Accounts.add method is used to randomly generate a new account:

You would likely add an existing account from a private key, as follows:

```shell
>>> accounts.add('0xca751356c37a98109fd969d8e79b42d768587efc6ba35e878bc8c093ed95d8a9')
<LocalAccount '0xf6c0182eFD54830A87e4020E13B8E4C82e2f60f0'>
```



## Compiling Contracts

Compiling contracts will result in compilation to the same project folder.

```shell
$ brownie compile

```





## Writing a Deployment Script[](https://eth-brownie.readthedocs.io/en/stable/deploy.html#writing-a-deployment-script)

Deployment scripts function in the same way as any other [Brownie script](https://eth-brownie.readthedocs.io/en/stable/interaction.html#scripts), but there are a couple of things to keep in mind when writing one for a non-local network:



1. Unless you are using your own node you will have to unlock a local account prior to deploying. This is handled within the script by calling [Accounts.load](https://eth-brownie.readthedocs.io/en/stable/api-network.html#Accounts.load). If you have not yet added a local account to Brownie, read the documentation on [local account management](https://eth-brownie.readthedocs.io/en/stable/account-management.html#local-accounts).
2. Most networks require that you to pay gas to miners. If no values are specified Brownie will calculate the gas price and limit automatically, but in some cases you may wish to manually declare these values.



```shell
from brownie import Token, accounts

def main():
    acct = accounts.load('deployment_account')
    Token.deploy("My Real Token", "RLT", 18, 1e28, {'from': acct})
```



```shell
$ brownie run deploy.py --network caduceus

```






