Configuring Truffle to work with Geth

We earlier configured Truffle to work with Ganache by adding the relevant details to truffle.js. We now want to add the equivalent details for our local Geth instance, so that Truffle can communicate with the public testnet. Underneath the development entry used by Ganache, add the following:

   rinkeby: {
host: "localhost",
port: 8545,
network_id: "4", // Rinkeby
from: "<your_account_address>",
gas: 5000000,
},

There are several things to note:

  • The network ID is 4, which is Rinkeby.
  • The from account is the new account created and funded in the steps described in the Running Geth on Rinkeby section.
  • The gas value is the most gas you want to spend on deploying the contracts (I have picked a value that will be high enough to cover the cost).

Before we deploy, we need to check that our account is unlocked and ready for use. To do this, you can run the following command with the password used at creation:

> personal.unlockAccount(personal.listAccounts[0],"<password>")

Having ensured the account is unlocked from our Geth console, we can then run the migration from our Terminal:

truffle migrate --network rinkeby

This should give the following output:

Running migration: 2_deploy_contracts.js
Deploying PacktToken...
... 0xb62b416b2d33235ca9e59693db0ed7c5485457a3fef77b8ac8b807c094619c5d
PacktToken: 0xe35949af5cd0c957c6ef54f92ef59dc311f40114
Deploying PacktTokenSale...
... 0x338b60c9a6d916695d8a30835a273a4625f7e3a084c5514818a19288b34431c4
PacktTokenSale: 0x601baf6e646cbe4fa91fdd6cc9619c6e5d538d22
Saving successful migration to network...
... 0x7ff158ab6d363441326a7402d3c137d322cd3a7283c732839579ab25f3cd8288

Saving artifacts...

In the preceding output, the longer hashes are the transactions that deployed the contracts, while the shorter hashes are the addresses at which the contracts now reside. Your hashes will differ from those here. These hashes can all be checked on Rinkeby's block explorer, https://rinkeby.etherscan.io.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset