wethio-documentation

Truffle

Learn how to use Truffle to deploy your smart contracts to a public ethereum network

Before starting, ensure that you have done the following:

  • Created a Truffle Teams account

  • Linked a repo that is a Truffle project

  • Got a passing build with Truffle teams

  • Have some Ropsten Ether

  • Network connection stability check

The Deployments Page

  1. Open your Truffle Teams Account, click on DEPLOYMENTS on the left navigation bar

  2. A list of repositories is displayed. Click the one you’d like to deploy

  3. Now you’re at the deployments page. You will see three columns: Commits, Staging, and Production

Commits: Shows a list of all commits that Truffle Teams is processing or processed, as a build. A status icon is present that indicates the status of the build, i.e. if it is in progress, failed, or successful

Staging: Contains a list of all testnet (i.e. Ropsten, Görli, Rinkeby, and Kovan)

Production: Contains a list of all Mainnet deployments

The First Deployment

Here we will guide you how to deploy an application to Ropsten

  1. Click on the parachute icon next to the commit you want to deploy

  2. A wizard will pop up; select Ropsten under Destination Network

  3. Press Connect Wallet

  4. In case you have not logged into MetaMask, a pop-up will appear.

  5. Press Connect to confirm the connection with Truffle Teams

In case you don’t see a button to start deploying, switch your MetaMask network to Ropsten and repeat the above steps

Now when you the wizard prompting for a Deployment Context.

  1. Set it to Create a New Deployment

  2. Press OK, START DEPLOYING button

It might take some time for the Truffle Team to start processing your deployment as they have to process many deployments simultaneously. Make sure you do not lose your internet connection in the meantime.

Once your deployment has started processing, you’ll see a pop-up displaying the list of steps Truffle Teams is doing to prepare for your deployment.

Once all the steps are completed, a screen with a list of your processed migrations appears. A pop-up from MetaMask is also there for your first transaction.

An easy-to-understand interface with MetaMask is visible that is like sending a transaction to any other dapp. Change the GAS FEE to be higher to make your transactions run quicker. For testnets like Ropsten, it’s affordable to always select the Fast option

When you’re satisfied with the transaction gas fee, press the Confirm button to send. As soon as the one transaction is confirmed, you’ll receive the next transaction. Repeat this process until you receive a message that your deployment is being finalized.

After a short while, a window with deployment results appears on the screen.

Your contracts are now deployed. Hit the Great! Go Back to Workflow button or directly close the wizard.

In the Staging column you can now see the results of your deployment. You can check the list of your deployed contracts and their addresses by clicking on the + Contracts bar on the bottom of the card

You can even access the Menu by clicking on the vertical 3 dots in the top right of the card. From the menu, you can:

  • Download a .zip file of your Truffle

  • .json artifacts used in your frontend web app

  • Graduate a deployment to production

  • Archive the deployment

Deployment Context

To be used for more advanced Truffle applications that use migration system to iteratively migrate more to the blockchain (instead of starting fresh)

In this, you can select an existing deployment on the same network that you’d like to use the deployed artifacts for. As it supports the concept of migrating your application, you can run the new migration scripts from the last deployment (i.e. the deployment context).

Graduating Deployments

Once you are satisfied with a particular deployment in Staging, you can select the Graduate option from the menu. After that the same build will be used as the basis of your deployment into Mainnet. Only selecting a different MetaMask is necessary, rest all steps are the same.

Once done, the production section will show a new deployment.

OpenZepplins

OpenZepplins is a collection of battle-tested libraries of smart contracts for Solidity development. It includes the most used implementations of ERC standards. Wethio’s ZRC20 and ZRC721 find the most obvious use of OpenZepplins.

Installation

  1. Install Truffle

    npm install -g truffle

  2. Use Truffle to initialize a new project

    mkdir MyProject && cd MyProject

    truffle init

  3. Install OpenZepplin in the new project

    npm init -y

    npm install --save-exact openzeppelin-solidity

Configure Solidity Compiler

OpenZepplin contracts require the Solidity 0.5.2 compiler (solc), however Truffle works with 0.5.0 by default. So it is necessary to configure Truffle to use 0.5.2 in order to use OpenZepplin for contracts.

Let’s add the following to ./truffle-config.js:

 module.exports = { compilers: { solc: { version: “0.5.2” } } }

Write Smart Contracts

As soon as you initialize a project with Truffle, it creates a ./contracts directory for your Solidity source code. Migrations.sol is present there for managing your contract migrations, don’t delete it.

Import OpenZepplin libraries

Starting to write your own smart contracts eases the use of OpenZepplin. As Truffle is dependent on NPM packages, Solidity libraries installed to ./node_modules are readily available without any configuration.

import 'openzeppelin-solidity/contracts/token/ERC20/ERC20.sol';

Deploy with Truffle

  1. Open the Truffle Console

    truffle develop

  2. Run Compile

  3. Migrate

Compilation generates the contract bytecode and application binary interface (ABI). Migration sends transactions to the network that create instances of our smart contracts.

Last updated