Sample Files

truffle_config.js

require('dotenv').config()
const { TruffleProvider } = require('@harmony-js/core')
//Local
const local_mnemonic = process.env.LOCAL_MNEMONIC
const local_private_key = process.env.LOCAL_PRIVATE_KEY
const local_url = process.env.LOCAL_0_URL;
//Testnet
const testnet_mnemonic = process.env.TESTNET_MNEMONIC
const testnet_private_key = process.env.TESTNET_PRIVATE_KEY
const testnet_url = process.env.TESTNET_0_URL
const testnet_0_url = process.env.TESTNET_0_URL
const testnet_1_url = process.env.TESTNET_1_URL
//Mainnet
const mainnet_mnemonic = process.env.MAINNET_MNEMONIC
const mainnet_private_key = process.env.MAINNET_PRIVATE_KEY
const mainnet_url = process.env.MAINNET_0_URL;
//GAS - Currently using same GAS accross all environments
gasLimit = process.env.GAS_LIMIT
gasPrice = process.env.GAS_PRICE
module.exports = {
networks: {
local: {
network_id: '2', // Any network (default: none)
provider: () => {
const truffleProvider = new TruffleProvider(
local_url,
{ memonic: local_mnemonic },
{ shardID: 0, chainId: 2 },
{ gasLimit: gasLimit, gasPrice: gasPrice},
);
const newAcc = truffleProvider.addByPrivateKey(local_private_key);
truffleProvider.setSigner(newAcc);
return truffleProvider;
},
},
testnet: {
network_id: '2', // Any network (default: none)
provider: () => {
const truffleProvider = new TruffleProvider(
testnet_url,
{ memonic: testnet_mnemonic },
{ shardID: 0, chainId: 2 },
{ gasLimit: gasLimit, gasPrice: gasPrice},
);
const newAcc = truffleProvider.addByPrivateKey(testnet_private_key);
truffleProvider.setSigner(newAcc);
return truffleProvider;
},
},
testnet0: {
network_id: '2', // Any network (default: none)
provider: () => {
const truffleProvider = new TruffleProvider(
testnet_0_url,
{ memonic: testnet_mnemonic },
{ shardID: 0, chainId: 2 },
{ gasLimit: gasLimit, gasPrice: gasPrice },
);
const newAcc = truffleProvider.addByPrivateKey(testnet_private_key);
truffleProvider.setSigner(newAcc);
return truffleProvider;
},
},
testnet1: {
network_id: '2', // Any network (default: none)
provider: () => {
const truffleProvider = new TruffleProvider(
testnet_1_url,
{ memonic: testnet_mnemonic },
{ shardID: 1, chainId: 2 },
{ gasLimit: gasLimit, gasPrice: gasPrice },
);
const newAcc = truffleProvider.addByPrivateKey(testnet_private_key);
truffleProvider.setSigner(newAcc);
return truffleProvider;
},
},
mainnet0: {
network_id: '1', // Any network (default: none)
provider: () => {
const truffleProvider = new TruffleProvider(
mainnet_url,
{ memonic: mainnet_mnemonic },
{ shardID: 0, chainId: 1 },
{ gasLimit: gasLimit, gasPrice: gasPrice },
);
const newAcc = truffleProvider.addByPrivateKey(mainnet_private_key);
truffleProvider.setSigner(newAcc);
return truffleProvider;
},
},
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
// Configure your compilers
compilers: {
solc: {
version: "0.5.8",
}
}
}

2_deploy_HarmonyERC20.js

var HarmonyERC20 = artifacts.require("HarmonyERC20");
module.exports = function(deployer, network, accounts) {
const name = "HarmonyERC20"
const symbol = "H20"
const decimals = 18
const amount = 1000000
const tokens = web3.utils.toWei(amount.toString(), 'ether')
deployer.then(function() {
return deployer.deploy(HarmonyERC20, name, symbol, decimals, tokens).then(function() {
});
});
};

HarmonyMintable.sol

pragma solidity >=0.4.21 <0.6.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
contract HarmonyERC20 is ERC20, ERC20Detailed, ERC20Mintable {
constructor(string memory _name, string memory _symbols, uint8 _decimals, uint256 _amount)
ERC20Detailed(_name, _symbols, _decimals)
public {
_mint(msg.sender, _amount);
}
}

HarmonyERC20.sol

pragma solidity >=0.4.21 <0.6.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
contract HarmonyERC20 is ERC20, ERC20Detailed {
constructor(string memory _name, string memory _symbols, uint8 _decimals, uint256 _amount)
ERC20Detailed(_name, _symbols, _decimals)
public {
_mint(msg.sender, _amount);
}
}

Package.json

{
"name": "harmony-erc20",
"version": "1.0.0",
"description": "Harmony sample ERC20 deploy",
"main": "truffle.js",
"dependencies": {
"@harmony-js/core": "^0.1.22",
"dotenv": "^8.2.0",
"tslib": "^1.10.0",
"openzeppelin-solidity": "^2.2.0"
}
}

.env

//LOCAL
//Local uses account one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7 on Shard 0
LOCAL_PRIVATE_KEY='45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'
LOCAL_MNEMONIC='urge clog right example dish drill card maximum mix bachelor section select'
LOCAL_0_URL='http://localhost:9500'
//TESTNET
//Account: one18t4yj4fuutj83uwqckkvxp9gfa0568uc48ggj7
TESTNET_PRIVATE_KEY='01F903CE0C960FF3A9E68E80FF5FFC344358D80CE1C221C3F9711AF07F83A3BD'
TESTNET_MNEMONIC='urge clog right example dish drill card maximum mix bachelor section select'
TESTNET_0_URL='https://api.s0.b.hmny.io'
TESTNET_1_URL='https://api.s1.b.hmny.io'
//MAINNET
//Please replace MAINNET_PRIVATE_KEY and MAINNET_MNEMONIC with your own!
//Account: one18t4yj4fuutj83uwqckkvxp9gfa0568uc48ggj7
MAINNET_PRIVATE_KEY='01F903CE0C960FF3A9E68E80FF5FFC344358D80CE1C221C3F9711AF07F83A3BD'
MAINNET_MNEMONIC='urge clog right example dish drill card maximum mix bachelor section select'
MAINNET_0_URL='https://api.s0.t.hmny.io'
GAS_LIMIT=3321900
GAS_PRICE=1000000000