Page cover image

🍨Testing with Brownie

A step-by-step guide for creating a Brownie project and deploying it to your private StealthTest environment.

Before you begin, please make sure to create your StealthTest environment and have access to the RPC URL and chain ID.

This document is intended to act as a quick start integration guide for new Brownie projects. If you already have an established Brownie project, skip to step 3.

For more information on Hardhat please access the documentation here: Brownie documentation

  1. Install Brownie.

    1. python3 -m pip install --user pipx

    2. python3 -m pipx ensurepath

    3. pipx install eth-brownie

    4. Run the command brownie to ensure the installation was successful.

user % brownie
Brownie v1.19.3 - Python development framework for Ethereum

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

Commands:
  init               Initialize a new brownie project
  bake               Initialize from a brownie-mix template
  pm                 Install and manage external packages
  compile            Compile the contract source files
  console            Load the console
  test               Run test cases in the tests/ folder
  run                Run a script in the scripts/ folder
  accounts           Manage local accounts
  networks           Manage network settings
  gui                Load the GUI to view opcodes and test coverage
  analyze            Find security vulnerabilities using the MythX API

Options:
  --help -h          Display this message
  --version          Show version and exit

Type 'brownie <command> --help' for specific options and more information about
each command.
  1. Create a new Brownie project.

    1. Create a new directory for your project: mkdir my-brownie-project

    2. Initialize your new project, we'll start from an ERC-20 template by running brownie bake-token

    3. You'll now have a folder called token, navigate there to compile your contracts.

my-brownie-project % cd token
token % ls
LICENSE			contracts		scripts
README.md		interfaces		tests
brownie-config.yaml	reports
build			requirements.txt
  1. Compile your contracts

    1. Contracts are located at ./contracts

    2. brownie compile

token % brownie compile
Brownie v1.19.3 - Python development framework for Ethereum

Compiling contracts...
  Solc version: 0.6.12
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
 - SafeMath
 - Token

Project has been compiled. Build artifacts saved at /Users/stealthtestuser/my-brownie-project/token/build/contracts
  1. Configure your project for StealthTest

    1. Add StealthTest RPC URL and ChainID as a new network

brownie networks add Ethereum stealthtest-eth host=https://<namespace>.ethereum.nameless.io chainid=12345
  1. Deploy your contract to StealthTest

    1. Run the following command:

token % brownie run token.py --network stealthtest-eth
Brownie v1.19.3 - Python development framework for Ethereum

TokenProject is the active project.

Running 'scripts/token.py::main'...
Transaction sent: 0xa862fd95830279bb09d1599ee08433f9e66fc481e39fbfd3866ecfafc18f6a20
  Gas price: 40.0 gwei   Gas limit: 573532   Nonce: 5
  Token.constructor confirmed   Block: 110   Gas used: 521393 (90.91%)
  Token deployed at: 0xB5f03cAb4f294096940B7bb0097B034a05D0e1f5

And that's it! You're now testing in private using StealthTest! πŸ’ͺ

Last updated

Was this helpful?