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?
If at any time you’re feeling lost, feel free to join us on Gitter and ask for assistance.
Let’s dive in!
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:
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.
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:
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.
If you receive an error message, you will need to install Python. If the version number shown begins 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.
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:
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.