Getting Started with Brownie: Part 1

Are you interested in buidling on Ethereum using Python? Heard good things about Brownie and want to try it out, but you’re not sure where to start?

Whether you’re just getting into programming, or you’re a curious JavaScript dev who always found the whole Python 2/3 thing a little too off-putting, this series of tutorials is for you! We’ll walk through all the steps required for installation and explore all the main areas of functionality. In no time you’ll go from feeling like this…

to this:

If at any time you’re feeling lost, feel free to join us on Gitter and ask for assistance.

Let’s dive in!

Installation

Before we can install Brownie we need to install some dependencies. Brownie relies on ganache-cli which is written in JavaScript. This means we’ll need to have both Python and Node.js installed. Lets start with the JavaScript parts.

Installing Node.js and npm

First, check to see if Node.js and npm are already installed. Open a terminal window and type the following commands:

node -v
npm -v

If either command returns an error message, we will need to install Node.js and npm. We need at least version 6.11.5 of Node.js in order to run Ganache.

Installing Ganache-CLI

Once Node.js is installed we are ready to install Ganache.

Ganache is a temporary blockchain that we can use for testing and development. It provides 10 unlocked accounts funded with 100 ether each, and mines transactions as they are broadcasted. It also lets us do magical things like reverting transactions and jumping forward in time, which is a huge help when unit testing.

Ganache comes in two flavours: a GUI version complete with a block explorer, and a more streamlined CLI version. For Brownie, we’ll be using the CLI version.

To install ganache-cli:

npm install -g ganache-cli

We can then verify that it installed correctly:

ganache-cli --version

Note that unlike Truffle, Brownie does not require you to launch Ganache yourself. Brownie will happily manage this process itself. Once installed, we can now go ahead and never think about Ganache again.

Installing Python and pipx

Okay, we’re half way there and we’re done with the not-Python bits. Depending on your background this could mean the hardest part is over or just getting started. But don’t worry, Python is a friendly snek 🐍

First, check to see if Python is already installed. If you’re using Linux or OSX there’s a very good chance that it is.

python --version

If you receive an error message, you will need to install Python. If the version number shown begins with 2, replace python with python3 in the above command and try running it again. We need at least version 3.6.0 in order to run Brownie.

Once Python is installed, we’re ready to install pipx. Pipx is a tool to help you install and run Python applications in isolated environments. It makes running and upgrading Brownie significantly easier than if we use regular pip.

To install pipx:

python -m pip install --user pipx
python -m pipx ensurepath

You might need to restart your terminal window after installing pipx, in order for the updated paths to take effect.

Installing Brownie

We’re finally there! With all the necessary dependencies in place, it’s time to install Brownie 😎 Type the following command into your terminal:

pipx install eth-brownie

It may take a minute or two as pipx installs all the required python packages. Once installation finishes, confirm that everything worked:

brownie

You should see something like this:

We’re in business! Congratulate yourself on a job well done.

When you’re ready, you can continue with Part Two, where we’ll create a new project and familiarize ourselves with some of Brownie’s main functionality.

You can also follow the Brownie Twitter account, read our other Medium articles, and join us on Gitter.