Gauss Docs
  • 🌐Getting Started
    • Welcome to Gauss
    • Whitepaper
      • Blockchain Providers Need to Do Better
        • Solving a Lack of Token Adoption
          • An Evolving Space With Untapped Potential
        • Security & Reliability
          • Curation & Vetting
            • Important Note For Brands
        • Token Creation
      • WHY BUILD WITH GAUSS?
      • Use Cases
        • Use Cases (Chart)
      • Roadmap
      • Technical Background and Blockchain Development
        • Why Another Blockchain?
        • Gauss 1.0: Built With Efficiency and a Strong Infrastructure to Launch Rapidly
        • Gauss 2.0: Added Functionality For a Better User Experiance
          • Noble Swap 2.0
          • NFTs in Gauss 2.0
          • Token Development Kit (TDK)
          • Gaming DAO
          • Omnipool
      • Token Economics
        • Gang Token Economics: Designed to Ensure Trust and Transparency
        • Token Locking Schedule
        • Reflections: Rewarding the Gauss Community
        • Charitable Allocations: Grants, Scholarships, & Financial Assistance
      • The Gauss Team
      • Important Definitions
      • DISCLAIMER
        • PURCHASER WARNING
        • PROMINENT STATEMENTS
        • FUTURE STATEMENTS
        • VALUE RISKS
        • NOT A SECURITY
    • How To Connect
      • Create Metamask Wallet
    • Links
  • ⚡Launching with Gauss
    • Benefits of Building with Gauss
      • Fostering an Environment for Success
      • Gauss Growth Grant Program
      • Gauss Liquidity Program
      • Ecosystem Integrity Fund
      • Client Referral Program
    • A Guide to Curation
      • Core Principles and Curation Guidelines
      • Curation Stages and Processing Fees
    • Building on Gauss
  • 🖥️Gauss Ecosystem
    • Gauss Chain
      • Polygon-Edge Overview
      • Architecture
      • Consensus
      • Client Modules
        • Blockchain
        • Minimal
        • Networking
        • State
        • TxPool
        • JSON RPC
        • Consensus
        • Storage
        • Types
        • Syncer
        • Sealer
        • Other Modules
      • Polygon-Edge Performance Reports
      • For Developers
        • Operate a Node
          • Local Install
          • Genesis Contract
          • Server Config
          • CLI Commands
          • Key Management
        • Run a Validator
          • Validator FAQ
        • Smart Contract Deployment Permissioning
        • Deploying Contracts
          • Remix
          • Truffle
          • Hardhat
          • Replit
    • Gauss Explorer
      • Features
      • Navigating the Explorer
        • Menus
        • Blocks
        • Transactions
      • Verifying a Smart Contract
        • Hardhat Plugin
        • Sourcify Plugin
        • OpenZeppelin Plugin
      • Interacting With Smart Contracts
      • Exporting Transactions
      • FAQ
      • For Developers
        • Gauss Explorer Dependencies
        • Deployment Guide
          • Smart Contract Verification
          • Cleaning an instance from the previous deployment
          • ENV Variables
          • Testing
        • APIs
          • Requests & Limits
          • GraphQL
          • ETH RPC
    • Noble Swap
      • Liquidity Boost Program
    • Tokens
    • Gauss NFTs
      • Ferro Cards
      • F.E.R.R.E.T. NFTs
    • Contests & Giveaways
    • Gauss Faucet
      • For Developers
    • Address List
  • 💡Additional Resources
    • Partnerships & Affiliates
    • Discord Channel
    • Contact Us
    • Learning Materials
      • Web3 Glossary
    • Media Kit
Powered by GitBook
On this page
  • Overview
  • What you will do
  • Prerequisites
  • Creating a Project
  1. Gauss Ecosystem
  2. Gauss Chain
  3. For Developers
  4. Deploying Contracts

Truffle

PreviousRemixNextHardhat

Last updated 2 years ago

Overview

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 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:

  • (packaged with Node)

Once we have those installed, we only need one command to install Truffle:

npm install -g 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

  1. Start by creating a new directory for this Truffle project:

mkdir MetaCoin
cd MetaCoin
  1. Download the MetaCoin box:

truffle unbox metacoin

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:

// SPDX-License-Identifier: MIT
// Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0
pragma solidity ^0.8.13;

import "./ConvertLib.sol";

// This is just a simple example of a coin-like contract.
// It is not ERC20 compatible and cannot be expected to talk to other
// coin/token contracts.

contract MetaCoin {
	mapping (address => uint) balances;

	event Transfer(address indexed _from, address indexed _to, uint256 _value);

	constructor() {
		balances[tx.origin] = 10000;
	}

	function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
		if (balances[msg.sender] < amount) return false;
		balances[msg.sender] -= amount;
		balances[receiver] += amount;
		emit Transfer(msg.sender, receiver, amount);
		return true;
	}

	function getBalanceInEth(address addr) public view returns(uint){
		return ConvertLib.convert(getBalance(addr),2);
	}

	function getBalance(address addr) public view returns(uint) {
		return balances[addr];
	}
}

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.

  1. In a terminal, run the Solidity test:

truffle test ./test/TestMetaCoin.sol
  1. Run the JavaScript test:

truffle test ./test/metacoin.js

Compiling the Contract

Compile the smart contract using the following command:

truffle compile

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.

const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
    },
    gil: {
      provider: () => new HDWalletProvider(mnemonic, `https://rpc.giltestnet.com`),
      network_id: 1452,
      confirmations: 2,
      timeoutBlocks: 200,
      skipDryRun: true
    },
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
        version: "0.8.13",
    }
  }
}

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

truffle compile
truffle deploy --network mati

Remember your address, transaction_hash and other details provided would differ. Above is just to provide an idea of the structure.

We will use one of Truffle's boilerplates which you can find on their page. creates a token that can be transferred between accounts.

Add test GANG to your wallet using . Next, run this command in the root folder of the project directory:

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 .

🖥️
Truffle
Truffle quickstart guide
Node.js v8+ LTS and npm
Git
Truffle Boxes
MetaCoin box
G.I.L. Faucet
G.I.L. Explorer