Blockchain Ethereum Developer Brownie Guide

Andre Vianna
My Blockchain Zone
Published in
3 min readDec 20, 2021

1. Ethereum Brownie

Brownie

Brownie is a Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.

Features

  • Full support for Solidity and Vyper
  • Contract testing via pytest, including trace-based coverage evaluation
  • Property-based and stateful testing via hypothesis
  • Powerful debugging tools, including python-style tracebacks and custom error strings
  • Built-in console for quick project interaction
  • Support for ethPM packages

Install

python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install eth-brownie$ brownie
Brownie - Python development framework for Ethereum

Usage: brownie <command> [<args>...] [options <args>]
brownie networks list

Ethereum
├─Mainnet (Infura): mainnet
├─Ropsten (Infura): ropsten
├─Rinkeby (Infura): rinkeby
├─Goerli (Infura): goerli
└─Kovan (Infura): kovan

Ethereum Classic
├─Mainnet: etc
└─Kotti: kotti

Arbitrum
└─Mainnet: arbitrum-main

Avalanche
├─Mainnet: avax-main
└─Testnet: avax-test

Binance Smart Chain
├─Testnet: bsc-test
└─Mainnet: bsc-main

Fantom Opera
├─Testnet: ftm-test
└─Mainnet: ftm-main

Harmony
└─Mainnet (Shard 0): harmony-main

Polygon
├─Mainnet (Infura): polygon-main
└─Mumbai Testnet (Infura): polygon-test

XDai
├─Mainnet: xdai-main
└─Testnet: xdai-test

Development
├─Ganache-CLI: development
├─Geth Dev: geth-dev
├─Hardhat: hardhat
├─Hardhat (Mainnet Fork): hardhat-fork
├─Ganache-CLI (Mainnet Fork): mainnet-fork
├─Ganache-CLI (BSC-Mainnet Fork): bsc-main-fork
├─Ganache-CLI (FTM-Mainnet Fork): ftm-main-fork
├─Ganache-CLI (Polygon-Mainnet Fork): polygon-main-fork
├─Ganache-CLI (XDai-Mainnet Fork): xdai-main-fork
└─Ganache-CLI (Avax-Mainnet Fork): avax-main-fork

❯ brownie pm install OpenZeppelin/openzeppelin-contracts@4.0.0
Brownie v1.17.2 — Python development framework for Ethereum

  1. 47MiB [00:02, 552kiB/s]
    Downloading from https://solc-bin.ethereum.org/linux-amd64/solc-linux-amd64-v0.8.10+commit.fc410830

TokenERC20.sol

  1. brownie init
  2. pip install eth-brownie
  3. https://eips.ethereum.org/EIPS/eip-20
  4. Create /contract/TokenERC20.sol
  5. brownie compile
  6. ganache-cli
  7. Create /scripts/1_deploy_token.py
  8. brownie run scripts/1_deploy_token.py

EasyToken.sol

Open Zeppeling Git Hub ERC20

// contracts/GLDToken.sol // SPDX-License-Identifier: MIT 
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract GLDToken is ERC20 {
constructor(uint256 initialSupply) public ERC20("Gold", "GLD") { _mint(msg.sender, initialSupply); } }
  1. brownie compile
  2. brownie-config.yaml
  3. brownie compile
  4. brownie run scripts/2_deploy_ez_token.py
  5. brownie run scripts/1_deploy_token.py — network rinkeby

--

--

Andre Vianna
My Blockchain Zone

Software Engineer & Data Scientist #ESG #Vision2030 #Blockchain #DataScience #iot #bigdata #analytics #machinelearning #deeplearning #dataviz