Brownie lets you write scripts to interact with your project. Scripting is especially useful for deploying your contracts to the main-net, or for automating processes that you perform regularly.
Every script should begin with
from brownie import *. This imports the instantiated project classes into the local namespace and gives access to the Brownie Brownie API in exactly the same way as if you were using the console.
To execute a script from the command line:
$ brownie run <script> [function]
Or from the console, use the
>>> run('token') # executes the main() function within scripts/token.py
Or the import statement:
>>> from scripts.token import main >>> main()
Scripts are stored in the
scripts/ folder. Each script can contain as many functions as you’d like. If no function name is given, brownie will attempt to run
Here is a simple example script from the
token project, used to deploy the
Token contract from
1 2 3 4
from brownie import * def main(): accounts.deploy(Token, "Test Token", "TEST", 18, "1000 ether")
See the Brownie API documentation for available classes and methods when writing scripts.