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.
See more: How to create an ethereum token
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.
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.
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 Vyper – Solidity 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 pytest – Pytest 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 tools – ETH Brownie includes python-style tracebacks and custom error strings.
- Built-in console – This feature ensures quick project interaction.
- Support for ethPM packages – Ethernet 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.
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.
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.
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?
Maybe you are interested: Litecoin vs. Ethereum: Which is Better? • Benzinga Crypto