jmrocco

3 min read - Posted 06 Mar 19

Smart Contract Utilities with ZeppelinOS: Deploying to Mainnet

In previous tutorials, we used our local development environment for testing. This tutorial describes how to change your code so that you can deploy to the Etehreum mainnet.

The first step is to install the truffle hdwallet provider. The wallet allows you to sign (authenticate) transactions.

Note: You must install the wallet in every project.

npm install truffle-hdwallet-provider

Next use Infura to gain access to a network node, you need to register for an account. Infura allows the user to remotely attach to a node on the network and run their application. Otherwise the user has to run the node on their computer.

Once signed in, create a new project and from the Endpoint drop down select mainnet or one of the test networks depending on where you want to deploy. Write down the project ID because we need it in a couple of steps.

Now we have a node and a wallet but we need an account to join the two together. Install Metamask, which allows you to create an account where you can store funds, run dApps, and sign transactions. Upon creation of your account you are given a mnemonic, aka secret phrase associated with your account. We will use this mnemonic later.

Now that you have your mnemonic, project ID, and account we can make changes to the configuration file. In the truffle-config.js file add the following:

const HDWalletProvider = require("truffle-hdwallet-provider");
const fs = require("fs");

let secrets;

if (fs.existsSync("secrets.json")) {
  secrets = JSON.parse(fs.readFileSync("secrets.json", "utf8"));
}

module.exports = {
  networks: {
    development: {
      network_id: "*",
      host: "localhost",
      port: 8545
    },
    rinkeby: {
      provider: new HDWalletProvider(
        secrets.mnemonic,
        "https://rinkeby.infura.io/v3/" + secrets.infuraProjectID
      ),
      network_id: "4"
    },
    kovan: {
      provider: new HDWalletProvider(
        secrets.mnemonic,
        "https://kovan.infura.io/v3/" + secrets.infuraProjectID
      ),
      network_id: "42"
    },
    ropsten: {
      provider: new HDWalletProvider(
        secrets.mnemonic,
        "https://ropsten.infura.io/v3/" + secrets.infuraProjectID
      ),
      network_id: "3"
    },
    main: {
      provider: new HDWalletProvider(
        secrets.mnemonic,
        "https://main.infura.io/v3/" + secrets.infuraProjectID
      ),
      network_id: "1"
    }
  }
};

You also need to create a secrets.json file within your project folder. Add your mnemonic and Infura and Project ID to it.

{
  "mnemonic": "mnemonic-here",
  "infuraProjectID": "project-id-here"
}

Now we can push to the mainnet or test net. If you want to deploy to a test net, replace mainnet with the name of your test net.

zos push --network mainnet

That's it!! Your contract is now published. To apply this to our previous tutorials we change the commands that say --network local to --network mainnet, as well as follow the steps outlined above.

Next Steps

Created with Sketch.Content is"CC-BY-SA 4.0" licensed
Article On-chain
Article Author

Juliette Rocco

Intern @Kauri

13

3

0

0 Comments
Related Articles
Smart Contract Utilities with ZeppelinOS: Installation and Use

In this tutorial, we install ZeppelinOS, deploy a simple contract and then update it. Prerequisites Node.js An understanding of Solidity the programming language for smart contracts. Truffle, a development framework for Ethereum to test and deploy smart contracts. Ganache, a personal blockchain installed to test and run our smart contracts. Installing After installing Node.js we are now ready to install ZeppelinOS. Using terminal do the following: Note: For Windows users, I recommend Powershell

Smart Contract Utilities with ZeppelinOS: Introduction