Testing your Ethereum DApp on Rinkeby with Truffle

Testing your Ethereum DApp on Rinkeby

When building your Dapp for Ethereum, you will commonly use testrpc for testing your app on a local blockchain. However, you will soon find you want to test the app on a live blockchain. Ethereum allows you to test on a network call Rinkeby before deploying your app live. In this guide, I’ll take your through a deployment on Rinkeby, including setting up your account, and testing your app.

This app uses Truffle and assumes you have done the following:

  1. Read about Ethereum: https://www.ethereum.org/
  2. Gone through the Pet tutorial with Truffle and MetaMask: http://truffleframework.com/tutorials/pet-shop

Download the Mist wallet

To start, you will need to sink the Rinkeby network locally and to have it running so we can send our app. Start by downloading the official Ethereum wallet on this page https://www.ethereum.org/.

alt text

Sync the Rinkeby Network

Once downloaded and installed, open the app and click Use Rinkeby.
alt text

Enter a password for your Rinkeby account.
alt text

Then take note of where your wallet info is stored.
alt text

Wait for the network to sync (this could take a few hours). Then click “Launch Application”.

Getting Ether

The next step is to request Ether from the Rinkeby Faucet. The faucet is setup to give users test out their applications on the network. On the actual Ethereum network, you will need to mine or buy ether to use your app.

To prevent malicious actors, Rinkeby asks users to use Social Media to request Ether. You can read more about there here: https://www.rinkeby.io/#faucet.

For this tutorial, we will use Twitter to request ether. Note that it can take a few hours to a few days depending on how much ether you request.

1. Start by getting your test account number from Mist

Select the wallets tab at the top and copy the address for one of your accounts. You should have one Main Account now if you have been following along.

alt text

This will load a populated tweet where you can enter your test network address to request Eth. Go ahead and past your address in the place of the 0x0000000000000000000000000000000000000000 address.

alt text

3. Paste the Link on the Faucet page

Go back to the faucet page. You will see a form at the top. Paste the link to your post there and click how much Ether you would like to request.

You will then be presented with a loading screen to show when your Ether will be funded.

alt text

Deploying Truffle App to Rinkeby

Now that we have some Ether, let’s deploy an app to test. Feel free to use an app you have already built, for this tutorial, I will use an example app from Truffle. We will then deploy the the Dapp to the test network Rinkeby.

1. Use the App from the Pet Shop Tutorial

Creating a Dapp is out of scope of this tutorial. We will be using the completed example from the Pet Shop tutorial: http://truffleframework.com/tutorials/pet-shop. Find that directory from your tutorial.

2. Install Geth

We will need the geth command line tool to run Rinkeby. Use the following url and find your install instructions for your platform: https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum

3. Run Rinkeby from the Command Line

Replace the address below with your test Ethereum address and the password with the one you used during Mist setup.

geth --rinkeby --rpc --rpcapi db,eth,net,web3,personal --unlock="0x0000000000000000000000000000000000000000"
--password <Yourpassword> --rpccorsdomain http://localhost:3000

4. Add Rinkeby to your Truffle deploy config

Be sure to add your test Ethereum address in place of the place holder.

// truffle.js

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*", // Match any network id
    rinkeby: {
      host: "localhost", // Connect to geth on the specified
      port: 8545,
      from: "0x0000000000000000000000000000000000000000", // default address to use for any transaction Truffle makes during migrations
      network_id: 4,
      gas: 4612388 // Gas limit used for deploys

5. Migrate your Truffle app to Rinkeby

truffle migrate --network rinkeby

6. View your contracts on Etherscan


Using your App

Okay, now we have successfully deployed our app on Rinkeby. The next thing to do is use it. We will simply run the app locally and switch Metamask to the Rinkeby test network. This will allow use to send transactions through Rinkeby rather than our local testrpc from before.

1. Start the app

We are running this locally, but you can deploy this Netlify, AWS, Azure, etc and Metamask will inject the web3 console to allow for use on the blockchain.

npm run dev

2. Import Mist Account into Meta Mask

Go to Mist and click File -> Backup -> Accounts. Click on rinkeby -> keystore. This is the file you will need.

alt text

Go to Metamask in your browser, select Rinkeby, import account then select the file above. Enter your password.

alt text

3. Use the app

Now open up your app and you are running on the Rinkeby test net!


There is a lot going on here, but most of it is one time set up with your Wallet. Once you have an account and Ether, it should be easy to test out future apps.

Let me know if you have any questions by commented below or messaging me on Twitter at @thehollidayinn


4 thoughts on “Testing your Ethereum DApp on Rinkeby with Truffle

  1. geth –rinkeby –rpc –rpcapi db,eth,net,web3,personal –unlock=”0x0000000000000000000000000000000000000000″
    –pasword –rpccorsdomain http://localhost:3000
    This command is give the fatle error :
    Fatal: Error starting protocol stack: datadir already used by another process


  2. Every time I run step 5 of Deploying Truffle App to Rinkeby I get the error insufficient funds for gas * price + value. When I try adjusting it, I get Error: exceeds block gas limit. I have tried many ways to fix this, but nothing seems to work. Any advice on how to approach this error?


    • Hey! Yea, this is a tricky one that I run into a bit.

      Some StackOverflow answers suggest increasing the limit, but that usually doesn’t work for me.

      I’d try the following:
      1. Check to see if you can deploy it on Ganace or another local testnet – if this works, then there might be something wrong with the limit if not continue
      2. Sometimes there is an error in the code so try commenting out chunks and deploying to local testnet until you can get something to deploy.
      3. If you don’t find a type or logic error from doing the above, you need to break down your contract into multiple contracts. Cryptokitties has some examples: https://medium.com/loom-network/how-to-code-your-own-cryptokitties-style-game-on-ethereum-7c8ac86a4eb3. Feel free to ping me with specifics if you get to this point.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s