Truffle
Overview
Truffle is a blockchain development environment, which you can use to create and test smart contracts by leveraging the Ethereum Virtual Machine. This guide aims at teaching how to create a smart contract using Truffle and deploying it on the EVM-compatible Gauss Induction Labs Testnet.
This tutorial is an adapted version of the Truffle quickstart guide article.
What you will do
Install and set up Truffle
Deploy contract on G.I.L. Testnet
Check the deployment status on the G.I.L. Explorer
Prerequisites
There are a few technical requirements before we start. Please install the following:
Node.js v8+ LTS and npm (packaged with Node)
Once we have those installed, we only need one command to install Truffle:
To verify that Truffle is installed properly, type truffle version
on a terminal. If you see an error, make sure that the npm modules are added to your path.
Creating a Project
MetaCoin Project
We will use one of Truffle's boilerplates which you can find on their Truffle Boxes page. MetaCoin box creates a token that can be transferred between accounts.
Start by creating a new directory for this Truffle project:
Download the MetaCoin box:
With that last step, you have created a Truffle project cointaining folders with contracts, deployment, testing, and configuration files.
This is the smart contract data from the metacoin.sol
file:
Notice that ConvertLib is being imported just after the pragma
statement. In this project, there are actually two smart contracts that will be deployed at the end: one is Metacoin, containing all the send and balance logic; the other is ConvertLib, a library used to convert values.
Testing the Contract
You can run Solidity and JavaScript tests.
In a terminal, run the Solidity test:
Run the JavaScript test:
Compiling the Contract
Compile the smart contract using the following command:
Configuring the Smart Contract
Before actually depolying the contract, you need to set up the truffle-config.js
file, inserting network and compilers data.
Go to truffle-config.js
and update the file with Polygon Mumbai network details.
Note that it requires mnemonic to be passed in for provider
. This is the seed phrase (or private key) for the account you would like to deploy from. Create a new .secret
file in the root directory and enter your 12-word mnemonic seed phrase to get started. To get the seed words from MetaMask wallet, you can go to MetaMask settings, then from the menu, choose Security and Privacy where you will see a button that says reveal seed words.
Deploying on G.I.L. Testnet
Add test GANG to your wallet using G.I.L. Faucet. Next, run this command in the root folder of the project directory:
Remember your address
, transaction_hash
and other details provided would differ. Above is just to provide an idea of the structure.
Congratulations! You have successfully deployed a Smart Contract using Truffle. Now you can interact with the contract and also check its deployment status on the G.I.L. Explorer.
Last updated