Skip to content

Latest commit

 

History

History
135 lines (114 loc) · 5.01 KB

08.md

File metadata and controls

135 lines (114 loc) · 5.01 KB
title actions requireLogin material
Deploy to Loom Testnet
checkAnswer
hints
true
editor
language startingCode answer
javascript
./truffle.js
// Initialize HDWalletProvider const HDWalletProvider = require("truffle-hdwallet-provider"); // 1. Initialize LoomTruffleProvider // Set your own mnemonic here const mnemonic = "YOUR_MNEMONIC"; // Module exports to make this configuration available to Truffle itself module.exports = { // Object with configuration for each network networks: { // Configuration for mainnet mainnet: { provider: function () { // Setting the provider with the Infura Rinkeby address and Token return new HDWalletProvider(mnemonic, "https://mainnet.infura.io/v3/YOUR_TOKEN") }, network_id: "1" }, // Configuration for rinkeby network rinkeby: { // Special function to setup the provider provider: function () { // Setting the provider with the Infura Rinkeby address and Token return new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/v3/YOUR_TOKEN") }, // Network id is 4 for Rinkeby network_id: 4 }, // 2. Put here the configuration for loom_dapp_chain } };
// Initialize HDWalletProvider const HDWalletProvider = require("truffle-hdwallet-provider"); //Initialize LoomTruffleProvider const LoomTruffleProvider = require('loom-truffle-provider'); // Set your own mnemonic here const mnemonic = "YOUR_MNEMONIC"; // Module exports to make this configuration available to truffle itself module.exports = { // Object with configuration for each network networks: { // Configuration for mainnet mainnet: { provider: function () { // Setting the provider with the Infura Rinkeby address and Token return new HDWalletProvider(mnemonic, "https://mainnet.infura.io/v3/YOUR_TOKEN") }, network_id: "1" }, // Configuration for rinkeby network rinkeby: { // Special function to setup the provider provider: function () { // Setting the provider with the Infura Rinkeby address and Token return new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/v3/YOUR_TOKEN") }, // Network id is 4 for Rinkeby network_id: 4 }, // Configuration for Loom loom_testnet: { provider: function() { const privateKey = 'YOUR_PRIVATE_KEY' const chainId = 'extdev-plasma-us1'; const writeUrl = 'http://extdev-plasma-us1.dappchains.com:80/rpc'; const readUrl = 'http://extdev-plasma-us1.dappchains.com:80/query'; return new LoomTruffleProvider(chainId, writeUrl, readUrl, privateKey); }, network_id: '9545242630824' } } };

In this chapter, we’re going to deploy our smart contract to the Loom Testnet, but before doing the deployment, some prep work is needed.

First, we should create our own Loom private key. The easiest way to do it is by downloading and installing Loom according to this tutorial.

Next, creating a private key is as as simple as this:

$./loom genkey -a public_key -k private_key
local address: 0x42F401139048AB106c9e25DCae0Cf4b1Df985c39
local address base64: QvQBE5BIqxBsniXcrgz0sd+YXDk=
$cat private_key
/i0Qi8e/E+kVEIJLRPV5HJgn0sQBVi88EQw/Mq4ePFD1JGV1Nm14dA446BsPe3ajte3t/tpj7HaHDL84+Ce4Dg==

Note: Never reveal your private keys! We are only doing this for simplicity's sake.

Updating truffle.js

The first thing we are required to do is to initialize loom-truffle-provider. The syntax is similar to the one we've already used for HDWalletProvider:

const LoomTruffleProvider = require('loom-truffle-provider');

Next, just as we did in chapter 5, we'll have to let Truffle know how to deploy on Loom testnet. To do so, let's add a new object to truffle.js

loom_testnet: {
  provider: function() {
    const privateKey = 'YOUR_PRIVATE_KEY'
    const chainId = 'extdev-plasma-us1';
    const writeUrl = 'http://extdev-plasma-us1.dappchains.com:80/rpc';
    const readUrl = 'http://extdev-plasma-us1.dappchains.com:80/query';
    return new LoomTruffleProvider(chainId, writeUrl, readUrl, privateKey);
    },
  network_id: '9545242630824'
}

Put it to the test:

  1. Add the line of code that initializes LoomTruffleProvider.

  2. Place the configuration for loom_testnet near the bottom of the file.