MetaCoin Demo Project

Next, clone the MetaCoin demo project, and install the dependencies:

Shell

git clone https://github.com/truffle-box/metacoin-box

cd metacoin-box

npm install @truffle/hdwallet-provider

Use your favorite editor to edit the truffle-config.js file. Replace its content with the following code snippet, which configures the Dnero local privatenet and the Mainnet.

JavaScript Code Block

const HDWalletProvider = require('@truffle/hdwallet-provider');
module.exports = {
mocha: {
enableTimeouts: false,
before_timeout: 480000
},
networks: {
Dnero_privatenet: {
provider: () => {
// private key for test wallet #1: 0x19E7E376E7C213B7E7e7e46cc70A5dD086DAff2A
var privateKeyTest1 = '1111111111111111111111111111111111111111111111111111111111111111';
// private key for test wallet #2: 0x1563915e194D8CfBA1943570603F7606A3115508
var privateKeyTest2 = '2222222222222222222222222222222222222222222222222222222222222222';
return new HDWalletProvider({
privateKeys: [privateKeyTest1, privateKeyTest2],
providerOrUrl: 'http://localhost:18888/rpc',
});
},
network_id: 5467,
gasPrice: 4000000000000,
},
Dnero_testnet: {
provider: () => {
// Replace the private key below with the private key of the deployer wallet.
// Make sure the deployer wallet has a sufficient amount of Dtoken, e.g. 100 Dtoken
var deployerPrivateKey = '12345';
return new HDWalletProvider({
privateKeys: [deployerPrivateKey],
providerOrUrl: 'http://164.92.98.151:15444/rpc',
});
},
network_id: 5467,
gasPrice: 4000000000000,
},
Dnero_mainnet: {
provider: () => {
// Replace the private key below with the private key of the deployer wallet.
// Make sure the deployer wallet has a sufficient amount of Dtoken, e.g. 100 Dtoken
var deployerPrivateKey = '12345';
return new HDWalletProvider({
privateKeys: [deployerPrivateKey],
providerOrUrl: 'http://164.92.98.151:15444/rpc',
});
},
network_id: 5467,
gasPrice: 4000000000000,
}
}
};

Run the MetaCoin Unit Test Suite against the DNERO Local Privatenet

First, we need to setup the DNERO local privatenet with the Dnero/Ethereum RPC Adaptor following this guide.

Recall that on the Dnero blockchain, Dtoken is the gas token, similar to Ether on the Ethereum blockchain. Thus, to run the unit test cases, we first need to send Dtoken to your wallet.

Shell

truffle deploy --network Dnero_privatenet --reset

Next we can run the unit test cases (sometimes the test could take 2-3 minutes to complete):

Shell

truffle test ./test/TestMetaCoin.sol --network Dnero_privatenet

truffle test ./test/metacoin.js --network Dnero_privatenet

Deploy the MetaCoin Contract to the Dnero Mainnet

First, modify the following line in the truffle-config.js file to replace the private key with the actual private key of the deployer wallet (should delete the key after use, do NOT commit the private key to GitHub):

JavaScript

var deployerPrivateKey = '12345';

Also, make sure the deployer wallet has a sufficient amount of DToken on the DNERO Mainnet (e.g. 100 Dtoken). Next, execute the command below to deploy the smart contracts to the Dnero Mainnet. In rare cases, the command might exit with an error. If that happens, simply re-execute the deploy command.

Shell

truffle deploy --network Dnero_mainnet –reset

Last updated