From 75722555082ea1b379ad4f620f19ab84c7ea100c Mon Sep 17 00:00:00 2001 From: app Date: Wed, 17 Apr 2019 13:10:55 +0530 Subject: [PATCH] documentation --- LICENSE | 2 +- README.md | 103 +++++++++++++++++++++++++++------------------------ package.json | 8 ++-- 3 files changed, 60 insertions(+), 53 deletions(-) diff --git a/LICENSE b/LICENSE index a6a1bbd..35c41e8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Aniket +Copyright (c) 2018 Aniket-Engg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index e398eb9..da02aa7 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,14 @@ [![Build status](https://travis-ci.com/Aniket-Engg/sol-verifier.svg?branch=master)](https://travis-ci.com/Aniket-Engg/sol-verifier) [![Coverage Status](https://coveralls.io/repos/github/Aniket-Engg/sol-verifier/badge.svg?branch=master)](https://coveralls.io/github/Aniket-Engg/sol-verifier?branch=master) [![npm](https://img.shields.io/npm/dt/sol-verifier.svg)](https://www.npmjs.com/package/sol-verifier) +![NPM](https://img.shields.io/npm/l/sol-verifier.svg) +[![Package Quality](https://npm.packagequality.com/shield/sol-verifier.svg)](https://packagequality.com/#?package=sol-verifier) # sol-verifier -Verifying a contract on etherscan make your contract global and eligible for reading and writing on Etherscan. sol-verifier is an npm package which can be used to verify the ethereum contracts on Etherscan. It internally uses the Etherscan API. - -## Prerequisites -Make sure you have: -* [Node.js](https://nodejs.org/en/) installed on your system -* Etherscan Ethereum Developer [API](https://etherscan.io/apis) key-token -* Address on which contract is deployed on the network -* Constructor parameters values (if applicable) +sol-verifier is an NPM package to verify the Solidity smart contracts on Etherscan. It works as a CLI tool and can be used inside the js file too. ## Install -As a dependency, to use inside the code: +As a dependency, to use inside a file: ``` npm install --save sol-verifier ``` @@ -27,76 +22,86 @@ As a global npm module, to use `sol-verifier` as an executable: npm install -g sol-verifier ``` -## Run +## How to use -### As CLI -sol-verifier has multiple available options some of them are required and some depends on the usecase. One can see all the available options by using `--help` option. +### As a CLI tool +sol-verifier has multiple available options. some of them are required and some depends on the usecase. One can see all the available options by using `--help` option. ``` $ sol-verifier --help Usage: sol-verifier [options] Options: -v, --version output the version number - -k, --key Add Etherscan API Key (required) + -k, --key Add Etherscan API Key (recommended but optional) -c, --contract Add Contract File Path (required) -a, --address Add Address of Deployed Contract (required) - -n, --network Add Ethereum Network on Which Contract is deployed (required) + -n, --network Add Ethereum Network on Which Contract is deployed (if applicable) -N, --contractName Add Contract Name if Passed File Contains More Than One Contract (if applicable) - -p, --constructParams [param1, param2,...] Add Constructor parameter values same as in deployment (if applicable) + -p, --constructParams [param1, param2,...] Add Constructor Parameter Values Same as in Deployment (if applicable) -o, --optimize Add This Flag to Optimize The Contract (optional) -h, --help output usage information ``` -In an extensive case, where you have a file containing more than one contract and contract have a constructor which accepts some values at the time of deployment, you can use following commands for verifying contract on Etherscan. +Keeping the user-friendliness in mind, sol-verifier process certain information internally until it is explicitly required. For example, in a minimum case, if someone deploys a contract as below on some Ethereum network(which exists only on one network), ``` -sol-verifier -k -c -a -n -p -N +pragma solidity ^0.5.7; + +contract SimpleStorage { + uint storedData; + + function set(uint x) public { + storedData = x; + } + + function get() public view returns (uint) { + return storedData; + } +} ``` -You can add flag `-o` to enable the optimization of contract. On successful verification, you will get response as : +by CLI, it can be verified with this command: ``` -Contract has been successfully verified. Your GUID receipt : zkelnp3uxnr4qg3tcxsbdt8jnbdl96jevcb268c5uru4nhmgqn +> sol-verifier -c -a ``` +That's it. -### By requiring in Node.js file -Require the module after installation. +In an extensive one, where you have a contract importing some other contracts and having constructor with parameters,it can be verified with this command: +``` +sol-verifier -k -c -a -n -p -N ``` -const verifier = require('sol-verifier'); +If contract is deployed by enabling optimization, flag `-o` can be used to enable the optimization during verification. On successful verification, you will get response as : ``` -Now create the request object to pass as: (Make sure keys of request object will be always same.) +Info: Contract has been successfully verified. ``` + +### By requiring in file +A request object will be passed to verify contract. See below: (Make sure keys of request object will be always same) +``` + const verifier = require('sol-verifier'); var data = { - key: 'etherscan-api-key', // Etherscan API key (required) - path : '/path/to/contract/file/sample.sol', // Contract file path(required) - contractAddress: '0x123456789.......', // Contract address (required) - network : 'mainnet/ropsten/rinkeby/kovan', // Ethereum network used (required) - contractName: 'Sample' // Contract name, applicable only if contract file has more than one contracts - cvalues : [constructor, values, in, array], // constructor value in array, applicable if contract has constructor - optimizationFlag: false // Depends how you have compiled your contract (Default: false) + key: 'etherscan-api-key', // Etherscan API key (required) + path : '/path/to/contract/contractName.sol', // Contract file path(required) + contractAddress: '0x123456789.......', // Contract address (required) + network : 'mainnet/ropsten/rinkeby/kovan', // Ethereum network used (required) + contractName: 'contractName' // Contract name, only if contract file has more than one contracts + cvalues : [constructor, values, in, array], // constructor values in array, only if contract has constructor + optimizationFlag: false // Set `true` to enable optimization (Default: false) }; - verifier.verifyContract(data).then(function(res){ - console.log(res); - }) - .catch(function(error){ - console.log(error); - }); -``` -Parameters not applicable in your usecase can be ignored. Success response will look like: -``` -{ status: '1', - message: 'OK', - result: 'zkelnp3uxnr4qg3tcxsbdt8jnbdl96jevcb268c5uru4nhmgqn' } + await verifier.verifyContract(data); ``` -You will get a different GUID (from above response) everytime. This GUID receipt can be used to track the status of verification in the bottom section [here](https://etherscan.io/sourcecode-demo.html). (Choose the right URL according to the used network) - -**Note:** Getting GUID back doesn't ensure the contract verification, unless it show `>> Pass - Verified` in the status while checking at above given link. -## Limitations +Parameters not applicable can be ignored. +## Points to remember * This doesn't provide support for libraries. * Works for solidity version `>0.4.11`. -* Doesn't support `import` statements in contract file. Use available packages to flatten the contract. * The Etherscan API that this module uses is in BETA state. +* Maximum time for processing verification request is 30 seconds. If request timed out, check final result on Etherscan itself. + +## Contribution +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/Aniket-Engg/sol-verifier/issues) -## Contribution/Suggestions -Each kind of contributions even a single suggestion or feedback makes the project mature and reliable, so any such contributions are most welcome! +Each kind of contributions even a single suggestion or feedback makes project mature and reliable. ## License [MIT](https://github.com/Aniket-Engg/sol-verifier/blob/master/LICENSE) + +### Powered by Etherscan.io APIs diff --git a/package.json b/package.json index abd3157..0d8b5b7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sol-verifier", - "version": "1.1.2", - "description": "Verify Solidity Contracts on Etherscan", + "version": "1.2.0", + "description": "Verify Solidity Smart Contracts on Etherscan", "main": "index.js", "scripts": { "lint": "eslint .", @@ -21,7 +21,9 @@ "solidity", "verifier", "ethereum", - "smart-contract" + "smart-contract", + "sol-verifier", + "contract-verification" ], "author": "Aniket-Engg", "license": "MIT",