6

I have a geth node that is connected to a private network on my computer that uses port: 8545. Hence, I have a smart contract that is tested using Brownie on the ganache-cli network.

Brownie is a Python framework for Ethereum smart contract testing, interaction and deployment.


=> I want to deploy a smart contract using Brownie, how can I do it?

1 Answer 1

6

Connecting to the Network

First, make sure that Brownie is able to connect to your private network. You will have to add a custom network to Brownie's network settings. Here is an example command that declares a live network with the name "private" at 127.0.0.1, port 8545:

brownie networks add live private host=https://127.0.0.1:8545 chainid=1337

You can use brownie networks --help for more information on possible settings.

Deploying your Contract

The simplest way to deploy is via a deployment script. Here is an example deployment script for a basic ERC20, taken from the documentation:

from brownie import *

def main():
    accounts[0].deploy(Token, "Test Token", "TEST", 18, "1000 ether")

Save your deployment script within the scripts/ folder of your project.

To run the script on your local network, use the --network flag. For example, to run a deployment script named deployment.py on a network named "private":

brownie run deployment --network private

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.