Xenea Docs
  • OVERVIEW
    • Summary of Xenea
    • Core Technology
      • PoD(Proof of Democracy)
      • DACS (Decentralized Autonomous Content Storage)
  • XENE Tokenomics 1.0
    • What is XENE?
    • XENE Tokenomics
    • XENE Max Supply
    • XENE Genesis Tokens
    • Mining XENE with PoD
    • XENE Burning Mechanism
  • WHITEPAPER
    • Abstract
    • Legal Disclaimer
    • Introduction
    • Basic Concepts of Blockchain
    • Current Blockchain Issues
    • General Description
    • Purpose and Uniqueness
    • Basic Functions of the Xenea
    • PoD Consensus Algorithm Overview
    • Xenea Blockchain Nodes: The Pillars of the Network
    • Block Reward Mechanism: Fair Distribution of Rewards
    • Specifications: A Deeper Dive into Xenea Blockchain
    • XENEA Wallet
    • DACS Node Architecture and Sustainable Generation Manager
    • Halving
    • Finality
    • Token Economics for Sustaining the Xenea
    • Token Allocation and Supply
    • Xenea Governance Overview
    • Future Works
    • Development Roadmap
  • TESTNET
    • How to Run a Test-Net Node
    • How to Connect to Kura Testnet
    • Claim Kura Testnet XENE
    • How to Deploy to Smart Contracts
      • Remix IDE
      • Hardhat
      • Truffle
  • OTHER DOCUMENTS
    • AML KYC Policy
Powered by GitBook
On this page
  • Truffle
  • Install Truffle
  • Requirements
  • Install Truffle
  • Creating a Project
  • Create a new directory for your Truffle project
  • Initialize your project
  • Create Contract
  • Coding Migrations
  • Configuring Truffle For Kura Testnet
  • Deployment
  • Reference​
  1. TESTNET
  2. How to Deploy to Smart Contracts

Truffle

PreviousHardhatNextAML KYC Policy

Last updated 1 year ago

Truffle

A world class development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.

This page will take you through the basics of creating a Truffle project and deploying a smart contract to a blockchain.

Note: This page is just a quick start based on a sample program; please refer to for more information on Truffle installation.

Install Truffle

Requirements

  • Windows, Linux, or macOS

Install Truffle

Warning: Avoid using the sudo command when installing Truffle, this can cause permission errors.

In a terminal, use NPM to install Truffle:

npm install -g truffle

You may receive a list of warnings during installation. To confirm that Truffle was installed correctly, run:

truffle version

Creating a Project

After ensuring Truffle is installed successfully, create your own project and name it something like "truffleApp".

Create a new directory for your Truffle project

mkdir truffleApp
cd truffleApp

Initialize your project

truffle init

Once this operation is complete, you’ll now have a project structure with the following items:

  1. contracts/: Directory for Solidity contracts

  2. migrations/: Directory for scriptable deployment files

  3. test/: Directory for test files for testing your application and contracts

  4. truffle-config.js: Truffle configuration file

  5. build (visible after compile): Compiled Solidity contracts with bytecode and ABI

Create Contract

Make sure you install HDWalletProvider which we will use later:

npm install @truffle/hdwallet-provider --save

we create a file for smart contract called HelloKura.sol inside the contracts directory:

pragma solidity ^0.8.0;

contract HelloKura {
   string public greet = "Hello Kura!";
}

Coding Migrations

To deploy our HelloKura contract on Kura Testnet, we have to create a migration to get the contract on the network. Create a file in the migrations folder named “1_deploy_contract.js”.

var HelloKura = artifacts.require("HelloKura");

module.exports = function (deployer) {
    deployer.deploy(HelloKura);
};

Configuring Truffle For Kura Testnet

  1. Go to truffle-config.js (located in root directory)

  2. Update with Kura Testnet details

require('dotenv').config();
const mnemonic = process.env.MNEMONIC;
const HDWalletProvider = require('@truffle/hdwallet-provider');

module.exports = {
  networks: {
    kura: {
      provider: () => new HDWalletProvider(mnemonic, `https://rpc-kura.cross.technology/`),
      network_id: 5555,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true,
      from: "0x(your kura testnet account address)"
    }
  },
  compilers: {
    solc: {
      version: "0.8.0"
    }
  }
};

Be aware that we need to declare mnemonic which is used by HDWalletProvider in the truffle-config.js file to verify the account supplying funds during contract deployment. To set mnemonic variable, you would set it as an environment variable in .env file in the root directory.

npm i dotenv
MNEMONIC="(Your secret recovery phase)"

We can find our secret recovery phase for our account in the Metamask by going through Settings, Security & Privacy, and then Reveal Secret Recovery Phrase.

Deployment

Finally, we have everything ready and we can compile the smart contract we made:

truffle compile
truffle migrate --network kura

We would see something like below to confirm our smart contract is deployed on Kura testnet.

We can confirm this also by looking at the explorer .

Reference

Truffle's documentation
Node.js v14 - v18
Subscan
​
Official Document for Truffle