Using Truffle

Interacting with Edgeware EVM using Truffle

Introduction

This guide walks through the process of deploying a Solidity-based smart contract to a Edgeware node using Truffle. Truffle is one of the commonly used development tools for smart contracts on Ethereum. Given Edgeware's Ethereum compatibility features, Truffle can be used directly with a Edgeware node.
This guide assumes that you have a running local Edgeware EVM node running in --dev mode..

Environment Prerequisites

Installed Nodejs and particular package manager like yarn or npm, rest we have batteries included in this tutorial. When you are ready, clone our tutorial repository with prepared stack for you
1
git clone https://github.com/edgeware-builders/tutorials tutorials;cd tutorials/truffle;yarn
Copied!
It will move to your cloned repository, install required packages and you are ready to go!
Let's take sneak peak to truffle-config.js in truffle/ directory
1
const HDWalletProvider = require("@truffle/hdwallet-provider");
2
const privKey = '1111111111111111111111111111111111111111111111111111111111111111';
3
4
module.exports = {
5
compilers: {
6
solc: {
7
version: "^0.6.0",
8
}
9
},
10
networks: {
11
development: {
12
provider: () => new HDWalletProvider({
13
privateKeys: [ privKey ],
14
providerOrUrl: "http://localhost:9933/",
15
}),
16
network_id: 2021,
17
},
18
}
19
}
Copied!
You notice few facts from here, our chainId is 2021 and we are using solc version above ^0.6.0.
Note We are using the same private key that we have been using in other guides, which comes pre-funded with tokens tEDG via the genesis config of a Edgeware EVM node running in --dev mode. The public key for this account is: 0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a.
The contract we will be deploying with Truffle is a simple ERC-20 contract. You can find this contract under truffle/contracts/HedgeToken.sol, it's content is showed here

[ERC-20 Contract]

1
// SPDX-License-Identifier: MIT
2
pragma solidity ^0.6.0;
3
4
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5
6
contract HedgeToken is ERC20 {
7
constructor(uint256 initialSupply) public ERC20("HedgeToken", "HEDGE") {
8
_mint(msg.sender, initialSupply);
9
}
10
}
Copied!
It's Simple ERC-20 contracted based on the OpenZepplin ERC20 contract that creates HedgeToken and assigns the created initial token supply to the contract creator.
You can notice initial supply in migrations/2_deploy.contracts.js, it contains the following:
1
var HedgeToken = artifacts.require("HedgeToken");
2
3
module.exports = function (deployer) {
4
deployer.deploy(HedgeToken, "21000000000000000000000000");
5
};
Copied!
21000000000000000000000000 is the number of tokens to initially mint with the contract, that is 21 Million with 18 decimal places. Since OpenZepplin v3.0+, there is default decimal 18 for SimpleToken.sol
Now let's go to the essential part! After you had installed necessary packages, continue in terminal with following command

Compile ERC-20 Contract

1
npx truffle compile
Copied!
What id does, it take OpenZepplin ERC20.sol token, compiles it with other referenced code in other OpenZepplin code, creates artifact (bytecode) and ABI (contract interface)

Deploying a Contract to Edgeware EVM Using Truffle

Now let's go to the hot stuff, deploy it to our Edgeware EVM
1
npx truffle --network development migrate
Copied!
Truffle_2
As you may see, we are using our development network from truffle-config.js. From migrate you'll notice there what our contract address is of our contract.

Reach us for more engagement

Glad you've made it through! 🥰 We are eager to guide your more on your exploration through Edgeware Ethereum combability feature. We are keen to hear your experience and suggestions you may have for us.. You can feel free to chat with us in the Edgeware's channels like Discord, Element and Telegram, we can help you out with issues you may have or project you may want to be funded through our Treasury program. Don't hesitate to share your feedback on our channels, there is always space to improve! 🙌
Last modified 2mo ago