This page may contain legacy content

To get our most up-to-date content please access our documentation

July 30, 2021

ETH Brownie Explained – What is Brownie?

Table of Contents

It almost seems like yesterday when the only ones talking about Ethereum were tech-savvy individuals and hardcore coders. However, these days, blockchain-based technology has spread all across the mainstream media. And since ETH has the second-largest market cap, it captures almost as much attention as Bitcoin. But unlike Bitcoin, which primarily offers a store of value, ETH serves as a coin to propel the creation of awesome decentralized apps. As a result, many major programming languages have already deployed various frameworks to support working with Ethereum infrastructure. And this is exactly what ETH Brownie is – a Python-based framework for developing and testing Ethereum dApps. Read on to learn 

In this article, we will take a closer look at various aspects of ETH Brownie to provide you with a proper understanding. Even if you decide to just skim over the content, you should easily answer the ‘What is Brownie?’ question.

Before we move on, we’d just like to point out that by no means is Python required to start creating epic dApps. In case you are not familiar with Python but know JavaScript, then we have great news for you. That good news is Moralis – which is a serverless, next-gen decentralized application platform that lets you build dApps with just JavaScript! This ultimate Web3 development platform enables you to create serverless applications with maximum ease fast. If you are ready to use your JavaScript knowledge to dive into a booming blockchain industry, create your free Moralis account today!

What is ETH Brownie?

Though we’ve covered the most straightforward definition of ETH Brownie in the introduction, it may not tell you a lot. This is especially true if you do not have a lot of experience with Python, blockchain, and programming in general. As such, we will do our best to provide you with a more in-depth view of ETH Brownie. That way, you will surely not start talking about chocolate square cakes when the “what is Brownie” question comes up.

What is Python?

Python is one of the most popular high-level coding or programming languages. It is object-oriented and interpreted with dynamic semantics. The latter in combination with a high-level built-in data structure makes Python highly attractive for Rapid Application Development. Moreover, it is also popular in use cases requiring scripting or glue languages to connect existing components together. 

One of the key selling points of Python is its simple and easy-to-learn syntax that focuses on readability. That makes maintenance of the code much easier and thus often reduces the costs. Furthermore, just like JavaScript, Python also supports various modulus and packages. This encourages modularity and enables code reuse for faster and simpler coding. 

Both, Python interpreter and its extensive standard library are available for free for all major platforms. Many programmers like Python because it eliminates the compilation step. This makes the edit-test-debug cycle incredibly fast. In case you’d like to learn more details about Python, we highly recommend you visit python.org

ETH Brownie Explained

Let’s first repeat the most-to-the-point definition of ETH Brownie as provided by the Read the Docs: “Brownie is a Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.” While this definition definitely answers the “what is Brownie” question, it surely requires some additional attention. To understand the above definition properly, you need to know what Python, smart contracts, and Ethereum Virtual Machine (EVM) are. We have covered Python above, so one down – two to go.

What are Smart Contracts? 

If you are familiar with Ethereum, you’ve most likely heard of smart contracts before. If nothing else, we’ve mentioned them in this article already. 

At their core, smart contracts are basically codified agreements between parties. This means that certain (pre-defined) conditions must be met for certain (pre-defined) executions to take place. Moreover, it is thanks to smart contracts that Ethereum has so many use cases. 

This pioneer application of blockchain technology opened a whole new horizon of Web3 applications (aka dApps) that are now running on many blockchains. Decentralized apps are the most exciting application of smart contract technology. For more useful information regarding smart contracts, make sure to check out our blog post covering all the details. 

What is EVM?

First, you need to understand that Ethereum Virtual Machine or EVM definition is not as simple as some sources may present it. However, looking at EVM as the entire Ethereum blockchain ecosystem with all connected computers running Ethereum clients is the best big-picture overview. Essentially, EVM is an environment, in which all Ethereum accounts and smart contracts exist. It defines all the rules required for valid states of the Ethereum blockchain.

To further your knowledge, we recommend reading our article answering what is Ethereum Virtual Machine. It covers virtual machines in more detail, which will deepen your understanding of EVM.

In the following section, we will take a closer look at the ETH Brownie. This will include covering some of its key features and the quickstart aspects of its application. But before we continue, we’d like to remind you that mastering Python and using ETH Brownie is by no means essential for developing awesome aApps.

By using Moralis, all you need is a basic knowledge of Web3, being skilled in JavaScript, and some open-source pieces of Software. This makes Moralis the most amazing shortcut to developing Web3 apps without the need to deal with complicated back-end aspects. If you want to speed things up and gain the edge, create your free account today.

A Closer Look at ETH Brownie

Now you have all the information required to confidently answer the “what is ETH Brownie” question. Thus, you are ready to take a closer look at this Python-based framework. Let’s start by covering the main ETH Brownie features.

ETH Brownie Features

The key ETH Brownie features are:

  • Full support for Solidity and VyperSolidity is a programming language created specifically for developing decentralized apps on Ethereum by Ethereum developers. Moreover, Vyper is a pythonic programming language specifically targeting EVM.
  • Contract testing (including trace-based coverage evaluation) via pytestPytest is a robust Python testing tool, which has very universal use cases. Essentially, it is a software test framework. This command-line tool automatically locates tests you’ve written, runs them, and reports results.
  • Via hypothesis it provides property-based and stateful testing Hypothesis is one of Python libraries. It’s designed to support developers creating unit tests.
  • Powerful debugging toolsETH Brownie includes python-style tracebacks and custom error strings.
  • Built-in consoleThis feature ensures quick project interaction.
  • Support for ethPM packagesEthernet Port Module or ethPM packages are used to distribute EVM smart contracts and projects.  

Brownie Quickstart Overview

The purpose of this ETH Brownie quickstart is to provide you with a big-picture overview of how to use this Python framework. We will take a quick look at some examples, which will give you a sense of how things function.

 

Creating a New ETH Brownie Project

Whenever you want to create a new project, you need to initialize the proper command. Basically, you create an empty folder, where you type the following:

$ brownie init.  

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

The above code creates a ‘token/’ subdirectory.

ETH Brownie Project Structure

All Brownie projects follow a similar structure, which includes these elements:

  • Contract sources: contracts/
  • Interface sources: interfaces/
  • Scripts for deployment and interaction: scripts/ 
  • Scripts for testing the project: tests/

Aside from the above directories, there are additional ones created. The latter Brownie uses to manage the project. These are:

  • Project data – compiler artifacts and unit test results: build/
  • JSON report files for use in the GUI: reports/

To ensure that all runs smoothly, you should never delete or edit files within the above folders.

Compiling Contracts Using Brownie

When you want to compile your ETH Brownie project, you need to use the following code:

$ brownie compile

The above command returns a specific output. Moreover, an example of it is shown below. Also, keep in mind that you can change the compiler version and optimization settings via the config file.

Another thing worth noting is that Brownie automatically compiles any new or changed source files every time programmers load it. As such, you do not need to manually run the compiler.

Brownie Core Functionality

The Brownie console is very useful. Especially, when programmers want to interact with smart contracts deployed on a non-local chain. Aside from interaction, the console is great for development and quick testing. Luckily for those familiar with Python, the console feels very similar to a regular Python interpreter. 

Once inside the project directory, you load the console by using this code:

$ brownie console

Brownie compiles your contracts, starts the local RPC client, and gives you a command prompt. From this point on you may interact with the network. This means you may use the full range of functionality of Brownie API. 

Using Brownie to Accessing Local Accounts

Whenever you want to use Brownie to access local accounts, you do so by using the ‘accounts’ command as shown below. The ‘accounts’ is essentially a list-like object that contains ‘Accounts’ objects, which are able to make transactions.

Use this example to better grasp the concept:

Brownie & 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.’

Brownie & Transactions

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

Below are a couple of examples.

ETH Brownie console also enables you to examine the events by using the ‘transactionReceipt.events’ operator. See the example below.

Brownie Scripts

Using ETH 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. 

Brownie Testing

As mentioned previously, ETH Brownie uses the ‘pytest’ framework to test contracts. This makes things relatively simple. Of course, as long as you follow the ‘rules,’ such as storing tests in the ‘tests/’ folder. The full suite for testing on ETH Brownie is done by using:

$ brownie test

Moreover, Brownie testing offers many fixtures, an option to handle reverted transactions, isolating tests, and more. 

So, what are your thoughts on ETH Brownie so far? We have to admit that it is a very useful framework. So, in case you want to dig deeper, visit eth-brownie.readthedocs.io.

On the other hand, you can also see that using Brownie can be quite overwhelming, especially if you do not know Python. Luckily, there is a much simpler way to deploy dApps.

Do I Need Brownie to Deploy dApps?

If you remember, we’ve mentioned Moralis in previous sections. We might be slightly biased since Moralis is ‘our baby,’ but we honestly believe it is the best Web3 development platform. If it weren’t, it wouldn’t get such impressive support and collaboration opportunities with many huge projects, including Chainlink.

Moralis offers you all you need to build, host, and scale killer dApps. Moreover, it offers you the fastest path from idea to mass-scale dApp as you can fully focus on creating a great user experience. While you let Moralis do all the heavy lifting. 

We know it sounds too good to be true, but it is really amazing. To show you the true power of Moralis, we even created a simple dApp in as little as three minutes

So, in case you are not a Python expert but know JavaScript, you really don’t want to miss out on this amazing opportunity. Let Moralis help you create spectacular Web3 apps! Oh, and you may want to check out detailed videos that can spark your creativity and provide useful insights on what to use Moralis for

What is Brownie? – Summary

Now you know all about working with Ethereum and Brownie, and you’re finally able to explain Brownie to others. Perhaps most importantly, you know that Moralis is how you should work with Brownie, and all other blockchain development for that matter. Our simple and to-the-point explanations for various programming and blockchain-related terms will hopefully give you insight into a broad range of subjects. Moreover, we’ve ensured to give you links to articles we know offer high-quality and proper information. At this point, you can surely answer the ‘what is Brownie’ question. You know that ETH Brownie is a Python-based framework for developing and testing Ethereum dApps. And since we’ve also covered a quickstart, you know how to get started.

However, we’ve also provided you with a much simpler alternative in Moralis, the one surely more suitable for you in case you do not know Python. As such, you now know what is your best option to create dApps fast, without wasting time on Web3 back-end development. In fact, you can use Moralis and Brownie to, e.g., create Ethereum tokens in four easy steps! What’s more, Moralis is the premier middleware that enables you to create dApps, and much, much more. What are you waiting for?

Moralis Money
Stay ahead of the markets with real-time, on-chain data insights. Inform your trades with true market alpha!
Moralis Money
Related Articles
October 5, 2022

Polygon Joins Moralis x Google Defining DeFi Hackathon as Gold Tier Sponsor

April 8, 2024

Moralis Launches ERC20 Owners Endpoint

April 9, 2024

Moralis Launches Wallet History Endpoint

March 28, 2024

Introducing Token Logos for Token API

November 30, 2022

Moralis Adds Support for Palm Network

April 18, 2024

Moralis Launches Moralis Nodes

October 27, 2022

Moralis Introduces Arbitrum Support

September 8, 2022

Introducing Self-Hosted Moralis Servers

November 15, 2022

Moralis Introduces Support for the Optimism Network