Skip to content

Latest commit

 

History

History
210 lines (163 loc) · 7.67 KB

10.md

File metadata and controls

210 lines (163 loc) · 7.67 KB
title actions requireLogin material
Deploy to Basechain
checkAnswer
hints
true
terminal
help commands
You should probably run `truffle migrate --network basechain`.
truffle migrate --network basechain
hint output
truffle migrate --network basechain
Starting migrations... ====================== > Network name: 'basechain' > Network id: 13654820909954 > Block gas limit: 0 1_initial_migration.js ====================== Replacing 'Migrations' ---------------------- > transaction hash: 0x5aaab85541e843d54926612e0b4f5faf2d48df8ad461b5f0de571565cabe8dc6 > Blocks: 0 Seconds: 0 > contract address: 0xc0eCB06312a20f9435E6Ed3B7eFD7bc0c0865BF2 > account: 0xE046eB99Cbe99d6760ff01304E25F1dD9116F558 > balance: 0 > gas used: 0 > gas price: 0 gwei > value sent: 0 ETH > total cost: 0 ETH > Saving migration to chain. > Saving artifacts ------------------------------------- > Total cost: 0 ETH 2_crypto_zombies.js ================= Replacing 'CryptoZombies' ----------------------- > transaction hash: 0xeed20de79685ab845e1e848bb871ce87d2fc532d7c87f40b9b25f2bf75b4e3a8 > Blocks: 0 Seconds: 0 > contract address: 0xDf2986bbDa42404C8f43A5851aF887B2A3a9CFaB > account: 0xE046eB99Cbe99d6760ff01304E25F1dD9116F558 > balance: 0 > gas used: 0 > gas price: 0 gwei > value sent: 0 ETH > total cost: 0 ETH > Saving migration to chain. > Saving artifacts ------------------------------------- > Total cost: 0 ETH

Congratulations! You've successfully deployed to Loom Testnet. But can you guess what's coming next?🤔

Yup, you're right! This chapter will walk you through the process of deploying to Basechain (that is our Mainnet).

Here's a brief rundown of what you'll do in this chapter:

  • Create a new private key.
  • Creating a new private key is pretty straightforward. But since we're talking about deploying to the main net, it's time to get more serious about security. Thus, we'll show you how to securely pass the private key to Truffle.
  • Tell Truffle how to deploy to Basechain by adding a new object to the truffle.js configuration file.
  • Whitelist your deployment keys so you can deploy to Basechain.
  • Lastly, we wrap everything up by actually deploying the smart contract.

Create a new private key

You already know how to create a private key. However, we must change the name of the file in which we're going to save it:

./loom genkey -a mainnet_public_key -k mainnet_private_key
local address: 0x07419790A773Cc6a2840f1c092240922B61eC778
local address base64: B0GXkKdzzGooQPHAkiQJIrYex3g=

Securely pass the private key to Truffle

The next thing we want to do is to prevent the private key file from being pushed to GitHub. To do so, let's create a new file called .gitignore:

touch .gitignore

Now let's "tell" GitHub that we want it to ignore the file in which we saved the private key by entering the following command:

echo mainnet_private_key >> .gitignore

Now that we made sure our secrets aren't going to be pushed to GitHub, we must edit the truffle.js configuration file and make it so that Truffle reads the private key from this file.

Let's start by importing a couple of things:

const { readFileSync } = require('fs')
const path = require('path')
const { join } = require('path')

Next, we would want to define a function that reads the private key from a file and initializes a new LoomTruffleProvider:

function getLoomProviderWithPrivateKey (privateKeyPath, chainId, writeUrl, readUrl) {
  const privateKey = readFileSync(privateKeyPath, 'utf-8');
  return new LoomTruffleProvider(chainId, writeUrl, readUrl, privateKey);
}

Pretty straightforward, isn't it?

Tell Truffle how to deploy to Basechain

Now, we must let Truffle know how to deploy to Basechain. To do so, let's add a new object to truffle.js

basechain: {
  provider: function() {
    const chainId = 'default';
    const writeUrl = 'http://basechain.dappchains.com/rpc';
    const readUrl = 'http://basechain.dappchains.com/query';
    return new LoomTruffleProvider(chainId, writeUrl, readUrl, privateKey);
    const privateKeyPath = path.join(__dirname, 'mainnet_private_key');
    const loomTruffleProvider = getLoomProviderWithPrivateKey(privateKeyPath, chainId, writeUrl, readUrl);
    return loomTruffleProvider;
    },
  network_id: '*'
}

At this point, your truffle.js file should look something like the following:

// Initialize HDWalletProvider
const HDWalletProvider = require("truffle-hdwallet-provider");

const { readFileSync } = require('fs')
const path = require('path')
const { join } = require('path')


// Set your own mnemonic here
const mnemonic = "YOUR_MNEMONIC";

function getLoomProviderWithPrivateKey (privateKeyPath, chainId, writeUrl, readUrl) {
  const privateKey = readFileSync(privateKeyPath, 'utf-8');
  return new LoomTruffleProvider(chainId, writeUrl, readUrl, privateKey);
}

// 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
    },

    basechain: {
      provider: function() {
        const chainId = 'default';
        const writeUrl = 'http://basechain.dappchains.com/rpc';
        const readUrl = 'http://basechain.dappchains.com/query';
        return new LoomTruffleProvider(chainId, writeUrl, readUrl, privateKey);
        const privateKeyPath = path.join(__dirname, 'mainnet_private_key');
        const loomTruffleProvider = getLoomProviderWithPrivateKey(privateKeyPath, chainId, writeUrl, readUrl);
        return loomTruffleProvider;
        },
      network_id: '*'
    }
  }
};

Whitelist your deployment keys

Before deploying to Basechain, you need to whitelist your keys by following the instructions from our Deploy to Mainnet guide. Don't worry about it right now, but keep in mind that you have to do this after you finish this tutorial.

We've gone ahead and performed all these steps and now we are ready to deploy to Basechain!

Put it to the test:

  1. Run truffle migrate --network basechain.

Awesome, you just deployed your smart contract to Basechain!👏🏻