DEV Community

Mrhili Mohamed Amine
Mrhili Mohamed Amine

Posted on


Save time developing smart-contracts with brownie

Seting up the Environment

First download python in my windows machine using the link below

The most important thing is to get the build tools necessary for the web3 library in my case i needed V++ 2019 build tools

Use the link bellow and scroll down to Tools for Visual Studio to get the online installer and install the needed version

Get a metamask wallet for the test only and create an account and register down

the passphrase, Account adress, The private keys

in the metamask network section reveal the testnet because we will use rinkbey test for this purpose

Get some etherium for the test using youre metamasc wallet here:

Create an account in

Create a project and name it however you like Just dont forget to turn the rinkby network after the creation process.
and write down the Project_id and the Project secret and the first endpoint

If you dont like Infura you can use :

Install Visualstudio code in the link bellow

Install some usefull extensions for solidity and python

Open a new project and start creatingthose files:

  • .env
  • brownie-config.yaml

You dont need to create a virtual environement just install pipx with administrator rules:

python -m pip install --user pipx
Enter fullscreen mode Exit fullscreen mode

reopen powershell and continue

python -m pipx ensurepath
Enter fullscreen mode Exit fullscreen mode

reopen powershell and install brownie

pipx install eth-brownie
Enter fullscreen mode Exit fullscreen mode

reopen powershell again and init required files for brownie

brownie init
Enter fullscreen mode Exit fullscreen mode

Now you have those new folders

  • build
  • contracts
  • interfaces
  • reports
  • scripts
  • tests

Environement variable

Add a required environement variable with the name

most be equal to youre INFURA_ID in the project created


The code for the SimpleStorage.sol is :
create the file under contracts folder

 // SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

contract SimpleStorage {

    uint256 favoriteNumber;

    // This is a comment!
    struct People {
        uint256 favoriteNumber;
        string name;

    People[] public people;
    mapping(string => uint256) public nameToFavoriteNumber;

    function store(uint256 _favoriteNumber) public {
        favoriteNumber = _favoriteNumber;

    function retrieve() public view returns (uint256){
        return favoriteNumber;

    function addPerson(string memory _name, uint256 _favoriteNumber) public {
        people.push(People(_favoriteNumber, _name));
        nameToFavoriteNumber[_name] = _favoriteNumber;
Enter fullscreen mode Exit fullscreen mode

In the code above we just have a favoriteNumber variable that we can check with retrieve function and modify with the store functionand we can associate someone name with a favorite number with addPerson function

the code of the deploy.pyshould be the same as:
create the file under scripts folder

from dotenv import load_dotenv


from brownie import accounts, config, SimpleStorage, network

def get_account():

    if network.show_active() == "development":
        return accounts.add(config["wallets"]["from_key"])
        return accounts.add(config["wallets"]["from_key_metama"])

def deploy_ss():

    print("ACCOUNT  =>",get_account())

    ss= SimpleStorage.deploy({"from": get_account()})

    trx =, {"from": get_account()})


    fav = ss.retrieve()

    print("FAV NOW   =>",fav)

def main():


Enter fullscreen mode Exit fullscreen mode

In the code above we are deploying the smart contract in the blockchain and interacting with it by storing the number 7 in favoriteNumber and the checking it

.env/Private keys

Now we should fill the necessary keys, you can escape the first two variables because it only needed in a local interaction with Ganache

.env file





Enter fullscreen mode Exit fullscreen mode


In the file brownie-config.yaml load where .env file are abd what the variable name for the private key

dotenv: "../.env"

  from_key: ${PRIVAT_KEY}
  from_key_metama: ${META_PRV}
Enter fullscreen mode Exit fullscreen mode


You just need a final step is running :

brownie run scripts/ --network rinkeby

I hope everything fine

if so check you contract here :

you can get the contract adress with the info given by youre brownie output

SimpleStorage deployed at: 0xsdfsdfrandomsdfsdf

for the needygreedy tutorialplease follow it here:

Top comments (2)

donemski profile image
Emski Don

Can you send me a message

mrhili profile image
Mrhili Mohamed Amine