Solidity has been the primary language for smart contract development. While writing various contracts, we maintain modules for code reuse and management. We imports the code from various files in our main file.
For various purposes like to verify contract on Etherscan (Although handles it internally using this), we need a straightened (One file with all imported files data) file. There are multiple CLI utilities available which do this but if one is required to handle it inside a javascript file, can be a right choice.
How to use
It is very simple to use. One need to require the module and provide the path of solidity file.
const Straightener = require('sol-straightener');
let result = await Straightener.straighten(<solidity/file/path>);
Import straightened file contents will be returned.
Support
Importing of file is possible in various ways. Currently sol-straightener handles import of files from:
- relative directories, e.g;
import "./lib/SafeMath.sol"; node_modulesdirectory, e.g;import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";- Github, e.g;
import "github.com/oraclize/ethereum-api/oraclizeAPI_0.5.sol";
Hope this will help Solidity developers out there.
If anyone thinks that there should be any other utility which can help Solidity developers, let me know in the comments below.
Thanks for reading!
Published at Sat, 11 May 2019 14:10:30 +0000