How To Deploy And Verify A Smart Contract From Remix
Tags: solidity, remix, ethereum
Published: 2022-03-23 21:25:57

Remix IDE is a convenient tool for building and testing your solidity smart contracts online. This short tutorial will explain how we can build and deploy our smart contract from Remix.

```solidity
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;
contract Destructor {
 uint256 public num;
    constructor(uint256 _num){
        num = _num;
    }
    function doWork() external
    {
        selfdestruct(payable(0));
    }
    function getNum() public view returns(uint){
        return num;
    }
}

```
## Deploying a contract
Above we have a simple `Destructor` contract which was built and tested using the online Remix IDE. To deploy this contract select the `Deploy & Run Transactions tab; select `injected Web3` as your environment. This will connect to the network that your wallet is connected to.


![Deploy Contract](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwd7d6gxpt67j1v7poxx.png)

Set the input value of the constructor function if your contract has one before deploying it. Clicking on deploy will open meta mask which will ask you to confirm the transaction. After confirming the transaction, the contract will be deployed to the network.

## Verifying deployed contract
You can verify your contract via Remix by using a plugin called `ETHERSCAN-CONTRACT VERIFICATION`. Click on the plugin manager icon. Search for the plugin `ETHERSCAN-CONTRACT VERIFICATION` and activate the plugin. After activation your Etherscan API key will be requested. 

You can obtain an API key on [etherscan](https://etherscan.io). Registering for a free account and create an API key.


![Pluggin Manager](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i6qpenru9n7c6lc81886.png)

After saving your key on the Etherscan-Contract Verification plugin, a screen will be presented where you enter the details of the just deployed smart contract.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eirf7hujiag9bwaicmx4.png)

You will have to present three (3) values to the Etherscan plugin which are the `contract to verify`, the `constructor arguments` and the `address of the deployed smart contract`. 

If the contract has a constructor with values supplied you will need to go to etherscan and retrieve the constructor argument bytes. We do this by copying the transaction hash which can be found on the console of remix.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/defwemd7o4aef48cbfm1.png)

Take the transaction hash and go to etherscan.io and input the hash on the search bar to retrieve the transaction. Remember if you deployed to a testnet you will have to search for your transaction on the testnet and not on the mainnet.

The transaction will be displayed. Scroll down on the transaction page and click on the `click to see more` button.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5rbbx6jqhv95zwtbu4co.png)

The more tab opens and you will see an `Input Data` textarea which contains the contract bytecode. We want to copy only the input byte of the constructor from this bytecode. The input byte is appended to the end of the bytecode. Search for the number `70033` inside the textarea. The input byte starts after the last `3` in `70033`. Copy the remaining number after the last `3` to the end. The copied number is the input byte. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p094unfq0u2toc3clz4x.png)

Go back to Remix IDE and input the copied byte inside the `Constructor Arguments` input box and also select the contract that you are verifying and input the contract address. Click on verify contract and the deployed contract will become verified.

Go to etherscan and search using the deployed contract address and you will see that your contract is now verified.