Flattening your Solidity files

Qayyum Rajan

This article is geared towards those that are beginning to interact with smart contracts in ethereum.

I’ve been through this a few times — and for those just starting in the space — this can somewhat be an annoying process — especially when trying to get verified on Etherscan.io

Typically your files will be in a combination of subfolders — and this article is meant to give a more detailed overview for those that want to get their contracts source code verified. We will do this from scratch for those not familiar with using npm and the terminal.

We will be using the POA Solidity Flattener found here (clone this to your local directory): https://github.com/poanetwork/solidity-flattener

First thing first is install NPM here.

To use some reference files — we can use some token contracts from openzepplin who provides an awesome collection of free smart contracts.

Open in Github Desktop, download the zip or clone the repo — whatever works for ya (I personally like Github Desktop).

Get the repo

We can use contracts/token/ERC20/ERC20Mintable.sol — This is a standard mintable token.

Mintable token

See how it starts with those two imports? Those are referencing other contracts in the repo. When it comes time to verify your source code, easy deployment of small contracts etc — what you want is a flattened file which holds all the imports in a single contract.

Open up your terminal and cd into your poa network folder (soldity-flattener) and then enter npm install.

You can now simply enter ‘npm start’ and add the file name of your smart contract (.sol file)

Get started

See that out folder…

Boom — flat file baby

Qayyum Rajan

Written by

Frontier/Blockchain/Macro/Data Science Co-Founder & Chief Data Officer at iComply Investor Services Inc.

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