Deploy and Verify a Contract to the Rinkeby Testnet — The Easy Way

Ebenezer Ackon
Jan 10 · 8 min read

This article aims to show you how to:

  1. Create a wallet and fill it with testnet Ether.
  2. Deploy a smart contract to the Rinkeby testnet.
  3. Verify the contract on Etherscan.
  4. Interact with and send transactions to the blockchain via the published contract.

What is Deploying, why Verify?

Deploying is the process in which a smart contract (solidity file) is written to the blockchain. It will stay there forever unless the code has a function that allows it to self destruct. Everyone can see this contract and interact with it once it has been deployed. The deployed contract is also immutable, meaning that it is impossible for it to be changed once it has been added to the blockchain. After deploying a contract, the next step is to verify it.

Verifying a contract is the process of checking if the generated bytecode actually matches the source code that was written. This is necessary for the community to trust the contract and to ensure that the code will do exactly what it claims to do. Security and transparency are the most important features when it comes to utilizing the blockchain. Once verified, the contract’s source code can be seen and publicly checked by anyone. A trusted site used to verify contracts is Etherscan.io.


What is the Rinkeby Testnet?

The Testnet is an alternative from the main blockchain, to be used for testing. Testnet Ether coins are separate and distinct from actual Ether coins, and are never supposed to have any value. This allows application developers or Ethereum testers to experiment, without having to use real tokens or worrying about breaking the main Ethereum blockchain. There are many different types of testnets that differ mostly by Consensus Algorithm. The testnet we will be deploying to is Rinkeby.

Rinkeby is an Ethereum Testnet. Rinkeby uses a PoA (proof-of-authority) algorithm to achieve consensus. Rinkeby is run by centralized nodes that could be shutdown at anytime. This is one reason why it’s only used for testing. Balances do not get transferred from one network to another. You cannot send Ether from the mainnet to testnets, the balance does not carry over.


Obtaining a Contract

I’ll be using my very own Greeter Contract. The Greeter contract allows those interacting with it to change the original string, read the current string that’s set, and kill the contract if necessary. You can access the greeter via cloning or downloading the zip.

Clone: git clone https://github.com/EbenezerGH/Greeter-Contract.git
Download Zip: https://github.com/EbenezerGH/GreeterContract/archive/master.zip
Source Code: https://raw.githubusercontent.com/EbenezerGH/Greeter-Contract/master/flattened/Greeter_flat.sol


Create a Wallet with Metamask on the Rinkeby Testnet

Metamask is a bridge that lets you run dApps from your computer. It injects a script from a javaScript library called web3.js which allows you to read and write requests to the blockchain from your browser. Web3 was written by the Ethereum core team so it is consistent with the already existing protocol. It also works as an HD wallet, a user can create and store wallet information with Metamask if they choose to do so.

  1. First we will need to download the official Metamask browser extension.
    https://metamask.io/.
  2. After downloading the extension, the fox icon should appear in your extensions tab. Click on it and go through the process of creating a password, accepting the terms of use, etc.
  3. Once that process is complete, change from Main Ethereum Network to Rinkeby Test Network, it’s time to get some Ether.
Metamask Chrome extension

Request Ether from the Rinkeby Faucet

Since testnet Ether doesn’t really hold any real monetary value, it’s possible to request Ether in increments. You give a public key to a faucet and it will distribute Ether to that address as long as you verify a social media profile. Verification of a social media profile is used as a method to prevent spam. My go-to Rinkeby faucet is https://www.rinkeby.io/#faucet.

  1. On a social media profile of your choice, make a post with your public address. MAKE SURE THE POST CONTAINS YOUR PUBLIC ADDRESS, NOT YOUR PRIVATE KEY.
  2. Copy and paste the URL to this post inside of the Give me Ether Field.
Google Plus post
https://plus.google.com/105649615752602866498/posts/9PusqoCKHXN

3. Confirm that the transaction went through by checking your public address on the Rinkeby Etherscan page https://rinkeby.etherscan.io/ . It may take some time depending on how congested the network is.

What is Etherscan?

Etherscan is the leading BlockExplorer for the Ethereum Blockchain. A BlockExplorer is basically a search engine that allows users to easily lookup, confirm and validate transactions that have taken place on the Ethereum Blockchain. We are independently operated and developed by a team of individuals who are truly passionate and excited about the kinds of decentralized information and infrastructure applications that Ethereum makes possible.

And just like you, we are “users” of the Ethereum Blockchain. Etherscan is not funded, operated or managed by the Ethereum Foundation but instead exists as an independent entity. The Ethereum Blockchain has a public ledger (like a decentralized database) which Etherscan.io indexes and then makes available this information through our site. Our mission is to facilitate Blockchain transparency by indexing and making searchable all transactions on the Ethereum Blockchain in the most transparent and accessible way possible.

Etherscan is not wallet service provider, we do not store your private keys and we have no control over the transactions that take place over the Ethereum network.

In addition, we also provide a set of load balanced robust API Services that can be used to either build decentralized applications or to serve as data feeds for Ethereum Blockchain information.

Source


Now, We can Deploy the Contract!

We will use Remix IDE to deploy our contract.

Remix can be used as a browser-based compiler and IDE. It enables users to build Ethereum contracts with Solidity language and to debug transactions.

Head to http://remix.ethereum.org and copy and paste the source code of the Greeter_flat.sol into the window. You can delete any code that’s already in the IDE window.

Note: It is important to copy the source file exactly as is. Any changes to the code (even a whitespace) can cause for an error when verifying the byte code later on.
Source Code

source code pasted into window

There are many different compile versions, but I recommend picking one closest to the solidity file’s pragma level. My pragma version is pragma solidity ^0.4.23 . So I will pick a version that does not exceed 4.23. version:0.4.23+commit.124ca40d.Emscripten.clang .

Looks like my code compiled with only 3 warnings now it’s time to run it.

Compile Successful
Ready to deploy

Most of the information should be filled out on the run screen. Metamask Automatically Injects a web3 script that contains your wallet information into the browser. The 3000000 gas limit is the max amount that I am willing to pay for the transaction. A standard Ethereum transaction costs 21000. The more computational work that needs to be done, the more you should raise your gas limit.

Note: We will opt out of enabling optimizations for this tutorial.

Click Deploy, we will add a string when we’re sending transactions later.

Confirmation Dialog

You should then see a confirmation screen. Confirm the transaction then check the logs in the IDE.

When you send tokens, interact with a contract, send ETH, or do anything else on the blockchain, you must pay for that computation. That payment is calculated in Gas and gas is paid in ETH.

The contract has been successfully deployed on the testnet. Going to the URL in the log redirects to the transaction hash. You can see your transaction information on Etherscan. Before we can interact with the contract, we need to verify it.


Verify The Contract

Unverified contract

Search your public address on Etherscan and go to the transaction that deployed the contract. Under the code tab you’ll see Verify and Publish. Click and it will redirect you to the screen below.

Verification

Copy and paste the whole flattened solidity file exactly as it is written. Fill in the name of the parent contract for contract name, and specify the compiler that was used. We did not add any libraries so we can scroll to the bottom and verify.

Verified contract information

The ABI is basically how you can encode Solidity contract calls for the EVM.

The Bytecode is the low level representation of the solidity file that was written.


Write to the Contract

Go back to the contract and click Address and you should see new tab options. Transactions, Code, Read Contract, Write Contract, Events.

Go to Write Contract and click Connect with Metamask. Write a greeting string, confirm the transaction and you’re done!

Unless you can read hexadecimal I recommend you select decode input data. You should see your message displayed in plain text.

https://rinkeby.etherscan.io/address/0xf4f6c2c246c08d4a1d7c8dbd7051a4c0555fe8e2#readContract

View the transaction from the below link.


Conclusion

The only difference between publishing from the mainnet and testnet is real Ether. Using Metamask and Etherscan, you can just select a different network other than Rinkeby. I enjoy using Metamask and remix because they are super lightweight tools and I don’t have to download the whole blockchain. They’re both powerful and capable of much more than was demonstrated.

There are many other ways to deploy a contract to the blockchain. There are also many more intricacies that vary per use case. I tried to be as general as possible and use a very simple contract. I also chose not to change too many optional parameters.

In my next article I will demonstrate how to use Web3 and Infura to interface with the Greeter contract we just verified. The code is already complete here.

Interfacing with an Ethereum Blockchain

Sharing Experiences with Smart Contract Development

Ebenezer Ackon

Written by

www.ebenezerackon.com

Interfacing with an Ethereum Blockchain

Sharing Experiences with Smart Contract Development

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade