3

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?

3

First, make sure that Brownie is able to connect to your private network. You will likely have to modify the configuration file within your project. Here is an example of configuration settings to declare to a persistent network with the name "private" at 127.0.0.1, port 8545:

network:
    networks:
        private:
            host: http://127.0.0.1:8545/
            persist: true

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" within the configuration file:

brownie run deployment --network private

If you have set persist: true in the project configuration settings for this network, Brownie will retain information about the deployed contract. When you run Brownie again, an object to interact with deployed contract will already be available. You can read more about persistence here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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