Developers Forum for XinFin XDC Network

Ivan_BlocksScan
Ivan_BlocksScan

Posted on

Learn How to Flatten a Smart Contract and Verify on BlocksScan.

Smart contracts are simply programs stored on a blockchain that run when predetermined conditions are met, and thanks to XRC Smart contracts where you can save up to 90% of your deployment transaction costs. Development on the XinFin XDC network has seen the platform register record growth, with the new smart contracts feature continuing to attract more developers. The increasing number of smart contracts on XDC Network validates that the network will likely emerge as a significant competitor to Ethereum, dominating the space as per the news on Bitcoinist.

There are many guides to teach creating smart contracts on XDC Network, but there’s another important factor with smart contracts which is to verify the deployed smart contract. In our recent article I have covered How to verify XRC20 Smart Contracts on BlocksScan in 2 simple steps. When a smart contract imports any other contract in the current contract, there are some cases where the verification of such smart contracts does not go through as usual. In order to verify such a smart contract, the contract needs to be flattened.

What is the exact purpose of Flatten a Smart Contract?
Flattening a smart contract refers to combining all Solidity code in one file instead of multiple source files such that, instead of having imports, the imported code is embedded in the same file. Let’s learn to flatten the smart contract for verifying the contract on XDC-Explorer, as it currently doesn’t support imports.

Learn to Flatten your Smart Contract with the following steps.
Step 1: Right-click on your Smart Contract and select Flatten.

Image description

Step 2: Once you have clicked on the Flatten, another “flat.sol” contract will be added to your screen.

Image description

Step 3: Now compile this TestContract_flat.sol file and deploy it on XinFin Remix.

Image description

Step 4: Once you have deployed your Smart contract on the XDC network, you can check on explorer by searching your Smart contract address.

Click on the Copy button to copy the smart contract address.

Image description

Step 5: Once you are on XDC Explorer, it will ask users to verify their contract. To verify the smart contract, Click on the “Verify And Publish” link. You will be automatically redirected to the Contract verification page with your Contract address.

Image description

Step 6: Now copy the code of TestContract_falt.sol file into the verification screen, check the Contract address, name, and the compiler version.

After confirming, click on the Submit button.

Image description

Step 7: Now, visit the Code tab to confirm that your Contract has been Verified successfully.

Image description

Used Sample Contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import “@openzeppelin/contracts/token/ERC20/ERC20.sol”;
contract TestToken is ERC20 {
constructor(uint256 initialSupply) ERC20(“Moon”, “MOON”) {
_mint(msg.sender, initialSupply);
}
}

Let us know how it works out for you!

For any queries, follow BlocksScan - Social channels:

Github
Twitter
Telegram
Facebook
Instagram

Discussion (0)