Brownie 101- New Project

M-Zohaib Nasir
3 min readMar 3, 2022

--

Creating a New Project

The first step to using Brownie is to initialize a new project. To do this, create an empty folder and then type:

brownie init

Structure of a Project:

Every Brownie project includes the following folders:

  • contracts/: Contract sources
  • interfaces/: Interface sources
  • scripts/: Scripts for deployment and interaction
  • tests/: Scripts for testing the project
  • brownie-config.yaml: Configuration file for 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

Brownie mixes

Aside from using the above code, you may also initialize “Brownie mixes” (these are Brownie project templates). There are many templates available. The code you can see below refers to the token mix. By initializing any Brownie mix, a specific subdirectory is created. Within it the template project downloads. Here’s how the code looks like:

brownie bake token

Compiling your Contracts:

To compile your project:

brownie compile

Brownie will compile your contracts, start the local RPC client, and give you a command prompt. From here you may interact with the network with the full range of functionality offered by the Brownie API .Also, keep in mind that you can change the compiler version and optimization settings via the config file(yaml file).

The console is useful when you want to interact directly with contracts deployed on a non-local chain, or for quick testing as you develop. It’s also a great starting point to familiarize yourself with Brownie’s functionality.

The console feels very similar to a regular python interpreter. From inside a project directory, load it by typing:

brownie console

Accounts:

Access to local accounts is through accounts, a list-like object that contains account objects capable of making transactions.

Contracts:

Brownie offers programmers a particular object, ‘ContractContainer,’ for each deployable contract in a project. Essentially, these objects are list-like elements used to deploy new contracts. A great example is provided below.

Whenever you deploy a contract, the console returns a ‘Contract’ object, which you can use to interact with the contract. Moreover, that object is added to the ‘ContractContainer.’

Transactions:

Yes, you’ve guessed it! ETH Brownie also offers the ‘TransactionReceipt’ object. It contains all relevant information regarding a transaction. On top of that, it also packs various methods to aid in debugging.

Brownie Scripts:

Using Brownie, you may also automate contract deployment and interactions by writing scripts. To do so, you need to place ‘from brownie import *’ at the beginning of your particular script. On top of that, you must store the script in the ‘script/’ folder.

importing
running script

Testing Your Project:

brownie test

& that’s it for today!

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

M-Zohaib Nasir
M-Zohaib Nasir

No responses yet

Write a response