Truffle

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 Truffle's documentation for more information on Truffle installation.

Install Truffle

Requirements

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:

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

Initialize your project

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:

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

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”.

Configuring Truffle For Kura Testnet

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

  2. Update with Kura Testnet details

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.

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:

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 Subscan.

Reference

Last updated