Developers
EVM Tools
Python Brownie
11min
brownie is a python based development and testing framework for smart contracts targeting the ethereum virtual machine https //solidity readthedocs io/en/v0 6 0/introduction to smart contracts html#the ethereum virtual machine brownie requires the ganache local test blockchain to be installed first else it will not work to install ganache you must install it globally using npm install g npm install g ganache installing brownie https //eth brownie readthedocs io/en/stable/install html#installing brownie the recommended way to install brownie is via pipx https //github com/pipxproject/pipx pipx is a tool to help you install and run end user applications written in python it’s roughly similar to macos’s brew, javascript’s npx, and linux’s apt pipx installs brownie into a virtual environment and makes it available directly from the commandline once installed, you will never have to activate a virtual environment prior to using brownie pipx does not ship with python if you have not used it before you will probably need to install it to install pipx python3 m pip install user pipx python3 m pipx ensurepath to install brownie using pipx pipx install eth brownie once installation is complete, type brownie to verify that it worked $ brownie brownie python development framework for ethereum usage brownie \<command> \[\<args> ] \[options \<args>] type brownie networks list to view a list of existing networks add caduceus to brownie https //eth brownie readthedocs io/en/v1 14 5/network management html#adding a new network to add a new network $ brownie networks add caduceus galaxytest host='https //galaxy block caduceus foundation' when declaring a new network, the following fields must always be included environment the category that the network should be placed in, e g “ethereum”, “ethereum classic”, or “development” id a unique identifier for the network, e g “mainnet” host the address of the node to connect e g https //galaxy block caduceus foundation the following fields are optional name a longer name to use for the network if not given, id is used timeout the number of seconds to wait for a response when making an rpc call defaults to 30 creating a new project to create a new project, create a new folder inside the new folder, type $ brownie init every brownie project includes the following sub folders contracts/ contract sources interfaces/ interface sources scripts/ scripts for deployment and interaction tests/ scripts for testing the project the following folders are also created, and used internally by brownie for managing the project you should not edit or delete files within these folders build/ project data such as compiler artifacts and unit test results reports/ json report files for use in the gui writing code for caduceus evm the contracts folder holds all contract source files for the project each time brownie is run, it checks for new or modified files within this folder if any are found, they are compiled and included within the project contracts may be written in solidity (with a sol extension) or vyper (with a vy extension) we recommend solidity due to the wider support base available you can write contracts and any dependencies inside the contracts folder working with accounts https //eth brownie readthedocs io/en/stable/core accounts html#working with accounts the accounts https //eth brownie readthedocs io/en/stable/api network html#brownie network account accounts container (available as accounts or just a) allows you to access all your local accounts \>>> accounts \['0xc0bce0346d4d93e30008a1fe83a2cf8cfb9ed301', '0xf414d65808f5f59ae156e51b97f98094888e7d92', '0x055f1c2c9334a4e57acf2c4d7ff95d03ca7d6741', '0x1b63b4495934bc1d6cb827f7a9835d316cdbb332', '0x303e8684b9992cdfa6e9c423e92989056b6fc04b', '0x5ec14fdc4b52de45837b7ec8016944f75ff42209', '0x22162f0d8fd490bde6ffc9425472941a1a59348a', '0x1da0dcc27950f6070c07f71d1de881c3c67ceaab', '0xa4c7f832254ee658e650855f1b529b2d01c92359','0x275cae3b8761cedc5b265f3241d07d2fec51c0d8'] \>>> accounts\[0] \<account object '0xc0bce0346d4d93e30008a1fe83a2cf8cfb9ed301'> each individual account is represented by an account https //eth brownie readthedocs io/en/stable/api network html#brownie network account account object that can perform actions such as querying a balance or sending eth the accounts add method is used to randomly generate a new account you would likely add an existing account from a private key, as follows \>>> accounts add('0xca751356c37a98109fd969d8e79b42d768587efc6ba35e878bc8c093ed95d8a9') \<localaccount '0xf6c0182efd54830a87e4020e13b8e4c82e2f60f0'> compiling contracts compiling contracts will result in compilation to the same project folder $ brownie compile writing a deployment script https //eth brownie readthedocs io/en/stable/deploy html#writing a deployment script deployment scripts function in the same way as any other brownie script https //eth brownie readthedocs io/en/stable/interaction html#scripts , but there are a couple of things to keep in mind when writing one for a non local network unless you are using your own node you will have to unlock a local account prior to deploying this is handled within the script by calling accounts load https //eth brownie readthedocs io/en/stable/api network html#accounts load if you have not yet added a local account to brownie, read the documentation on local account management https //eth brownie readthedocs io/en/stable/account management html#local accounts most networks require that you to pay gas to miners if no values are specified brownie will calculate the gas price and limit automatically, but in some cases you may wish to manually declare these values from brownie import token, accounts def main() acct = accounts load('deployment account') token deploy("my real token", "rlt", 18, 1e28, {'from' acct}) $ brownie run deploy py network caduceus