DEV Community

Owanate Amachree
Owanate Amachree

Posted on

How to verify a smart contract on the RSK Block Explorer

banner image

Originally published on the RSK Developers Portal.

Smart contracts are a means to execute code and store data on a blockchain.
To understand how smart contracts work, read What is a Smart Contract?

Source code verification provides transparency for users interacting with smart contracts. By uploading the source code, a block explorer will match the compiled code with that on the blockchain.

Once verified, a smart contract or token contract's source code becomes publicly visible and thus independently verifiable. This creates transparency and trust.
It also makes it more convenient for other developers to interact with your smart contracts.

In this tutorial, we will verify a smart contract, using the following steps:

  1. Connect metamask to RSK Explorer
  2. Get tRBTC using the RSK faucet
  3. Use remix compile and deploy the Smart Contract at RSK testnet
  4. Verify the Smart Contract on the RSK Explorer

Getting started

To connect Metamask to RSK Testnet, compile and deploy a smart contract, follow the steps in Using remix and metamask with RSK Testnet

As mentioned in the steps above, this is the smart contract below we will compile and deploy, it is called SimpleStorage.sol which has:

  • A variable storedData to store a number
  • A function get() to return the number stored at variable storedData
  • A function set() to change the number stored at variable storedData
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.7;

contract Contract {
     uint public x;

     constructor (uint _x)public{
        x = _x;
    }

    function increment() external {
        x++;
    }

    function add(uint one) external view returns(uint){
        // return the state variable
        return x + one;
    }
}
Enter fullscreen mode Exit fullscreen mode

Prepare the compiler settings in Remix

In Remix, ensure that the compiler setting used for the contract is same as the one in Remix. In this tutorial, we used version 0.8.7 of the Solidity compiler, solc.

You do this by clicking on the solidity icon by the left navigation in remix, and selecting the compiler version, this looks something like: 0.8.7+commit.e28d00a7 in the dropdown menu.

Compiler2

Note that the exact version of the compiler,
plus the other details here are critical during verification.
We'll use this later.

Verifying the smart contract

Upon contract creation, you will receive an address to check a pending transaction. Visit the RSK Explorer and paste the transaction hash into the search field.

In this article, we'll use the transaction hash:
0x843c7fc61ef2d678b36bb6662f610426a60ca484443231c3347c1896e03dfd49

Tx Hash

To verify the smart contract, we need to locate the contract address, to do this, scroll down to find the contract address.

Show contract address

Click on this address to open up the contract details.

Contract details

Click on Code

Code view

This shows the bytecode for the contract.

If another developer sees this,
they are unlikely to be able to interact with your smart contract,
as this is not human readable.
Let's improve this by performing verification.

Smart contract code is usually written in a high level programming language such as Solidity.
This code gets compiled to something called the bytecode which gets deployed to the RSK blockchain.
The nodes that comprise the RSK blockchain network execute this bytecode.
What is actually stored on the blockchain is not the original code written in Solidity,
but rather this compiler output.

Click on Verify Contract

Verify contract

Fill in the details below, enter contract name, upload the source file called SimpleStorage.sol.

Verify contract details

Check that the compiler version matches the version selected in remix, as shown in the images below;

Compiler settings - remix

Compiler settings - explorer

Fill other info, such as constructor arguments, libraries, and EVM encoded arguments (if available).

Note that the SimpleStorage.sol smart contract
does not have any constructor arguments, so this is left blank.

Click on Verify.

Verify contract

Verification in progress

Contract successfully verified.

Successful verification prompt

Once contract is successfully verified, click on "go to contract page". You'll notice a checkmark is now present beside Code which wasn't there previously.

Code checkmark

You can click on it to see more details of the contract.

Contract details

You'll also be able to see the compiler settings.

Compilation settings

Congratulations, you have successfully verified a smart contract on the RSK Block Explorer. To see a live example check out the one used in this article:
0x111b836d63e507a45dee556b10aa17ef16d423ae.

Top comments (1)

Collapse
 
venustar1228 profile image
venustar1228

What should I fill in Library name and Library address?