Coder Social home page Coder Social logo

aniket-engg / sol-verifier Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 15.0 731 KB

Verify Solidity smart contracts on Etherscan

License: MIT License

JavaScript 100.00%
solidity solidity-contracts etherscan etherscan-api sol-verifier verification-code

sol-verifier's Introduction

npm version Build status Coverage Status npm npm NPM Package Quality

sol-verifier

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 a file:

npm install --save sol-verifier

As a development dependency, to use it as <project_root>/node_modules/.bin/sol-verifier:

npm install --save-dev sol-verifier

As a global npm module, to use sol-verifier as an executable:

npm install -g sol-verifier

How to use

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 <etherscan-api-key>                    Etherscan API Key (recommended but optional)
  -c, --contract <path-to-solidity-contract-file>  Contract File Path (required)
  -a, --address <contract-address>                 Address of Deployed Contract (required)
  -n, --network <network>                          Ethereum Network on Which Contract is deployed (if applicable)
  -N, --contractName <contract-name>               Contract Name if Passed File Contains More Than One Contract (if applicable)
  -p, --constructParams [param1, param2,...]       Constructor Parameter Values Same as in Deployment (if applicable)
  -r, --runs <runs>                                Optimizer Runs (optional, default 200)
  -e, --evmVersion <evm-version>                   See valid options: https://solidity.readthedocs.io/en/latest/using-the-compiler.html#target-options (optional, default compiler-default)
  -l, --licenseType <license-type>                 Valid codes 1-12, see https://etherscan.io/contract-license-types (optional, default 1=No License)
  -o, --optimize                                   Add This Flag to Optimize The Contract (optional)
  -h, --help                                       output usage information 

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),

pragma solidity ^0.5.7;

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

by CLI, it can be verified with this command:

$ sol-verifier -c <contract-file-path> -a <contract-address>

That's it.

When you have a contract importing some other contracts and having constructor with parameters, it can be verified with this command:

$ sol-verifier -k <etherscan-api-key> -c <contract-file-path> -a <contract-address> -n <network i.e. mainnet, ropsten etc.> -p <constructor-params-values as: [param1,param2]> -N <contract-name>

If contract is compiled & deployed by enabling optimization, flag -o can be used to enable the optimization during verification. On successful verification, you will get response as :

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/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
        evmVersion: 'istanbul',                         // See valid options: https://solidity.readthedocs.io/en/latest/using-the-compiler.html#target-options (optional, default compiler-default)
        runs: 200,                                      // Optimizer Runs (optional, default 200)
        licenseType: 1,                                 // Valid codes 1-12, see https://etherscan.io/contract-license-types (optional, default 1=No License)
        optimizationFlag: false                         // Set `true` to enable optimization (default false)
    };

    await verifier.verifyContract(data);

Parameters not applicable can be ignored.

Note: In case of array as constructor parameters, pass values as: [[v1, v2], v3, v4] (This feature is available since version v2.1.0)

Points to remember

  • Add specific version with ^ in your contract pragma. Version should be same as the compiler version used while contract deployment.
  • This doesn't provide support for libraries.
  • Works for solidity version > 0.4.11.
  • 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

Each kind of contributions even a single suggestion or feedback makes project mature and reliable.

License

MIT

Powered by Etherscan.io APIs

sol-verifier's People

Contributors

aniket-engg avatar rohitsethii avatar timdaub avatar ukstv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sol-verifier's Issues

Does not support array parameters

The package, unfortunately, does not support bytes32[] parameter, and based on source code it does not support any array parameters.

Constructor Arguments - Fail - Unable to verify

The verification process fails when contract needs constructor arguments during verification.
I have deployed my contract using ether.js library. The verification process fails only for the contracts having constructor with arguments.

Contract Deployed using Ether.js:

let factory = new ethers.ContractFactory(contractABI, contractBytecode, wallet);
let contract = await factory.deploy(tokenSymbol, projectName, numOfTokens);

tokenSymbol, projectName, numOfTokens are the arguments for contract constructor

Inputs for sol-verifier:

var data = {
                key: etherscanAPIKey,
                path : path.join(__dirname, '../../ERC20-Mintable-Contract/erc20_mintable_contract.sol'),
                contractAddress:  contractAddress,
                network  : contractConfig.PROVIDER,
                contractName: contractName,
                cvalues: [tokenSymbol, projectName, numOfTokens],
                optimizationFlag: false
};

The same arguments I am passing while verification as that while deploying smart contract.

Output:

{
    "status": false,
    "message": "Fail - Unable to verify"
}

Contracts for reference:
0xa7a3373419dc09740a6D5c7c308230aB37581984 [Manually Verified with etherscan.io]
0x5Cb0832FA136486E15a2271E06f341c81f7d8602 [Fails to verify using sol-verifier]

I am sure this fails because of constructor arguments, because I tried one without arguments and it passed.

Thanks!

Add maxlimit for returning final response

As now we are showing the user final response of contract verification by tracking the GUID status, we should put the a maxlimit on time.
In EtherScan API documentation, it says

// Average time of processing is 30-60 seconds

It will be fine to set it for 60 seconds and throw with a message afterwards.

Identify network using contract address

In the trail of making user friendly and to let the user provide minimum options, lets make the network option optional.
We can check the existence of code on each network for provided contract address. If we get code only on one network, we will process with it. If there are more, we will ask user to enter specific option.

Add a dedicated developer API Key

For some newbies and make it quick usable, one Etherscan developer API key will be added for default. So user provided API key will be optional.
Although it would be recommended to use a personal/project Etherscan API key.

Unable to verify with sol-verify release v1.2.0

Current sol-verify version: v1.2.0
Current solidity version: ^0.4.18;

Payload:

{ 
    key: 'XXXXXXXXXXXXXXXXXXXXXX',
    path: '/private/var/www/html/blockchain/konkrete_node/ERC20-Mintable-Contract/erc20_mintable_contract.sol',
    contractAddress: '0xBa69648023f5ca52f93bD9d1E48854c1E82ebe8b',
    network: 'ropsten',
    contractName: 'konkrete6',
    cvalues: [ 'TSTM', 'Happy Project TSTM/projects/2/interest', 12345600 ],
    optimizationFlag: false 
}

Output:

{ 
    status: '0',
    message: 'NOTOK',
    result: 'Fail - Unable to verify' 
}

I am using contract named constructor instead of keyword.

Introduce updates

  • Add new solidity versions
  • Fix parser version
  • Use ethers.js to encode construcutor parameters

Cannot read property 'sendPayload' of null

command :
sol-verifier -k <etherscan API key> -c ./ballot.sol -a 0x1d1a5e345d14aa73a14bf55bb965912032209ff7 -n ropsten -p [4]

Expected : should return the success status with GUID receipt.

Actual : throws error related to web3 provider

/usr/local/lib/node_modules/sol-verifier/node_modules/web3-providers/dist/web3-providers.cjs.js:49
if (provider.sendPayload && provider.subscribe) {
^

TypeError: Cannot read property 'sendPayload' of null
at ProviderResolver.resolve (/usr/local/lib/node_modules/sol-verifier/node_modules/web3-providers/dist/web3-providers.cjs.js:49:20)
at Web3.AbstractWeb3Module (/usr/local/lib/node_modules/sol-verifier/node_modules/web3-core/dist/web3-core.cjs.js:24:51)
at new Web3 (/usr/local/lib/node_modules/sol-verifier/node_modules/web3/dist/web3.cjs.js:30:68)
at Object. (/usr/local/lib/node_modules/sol-verifier/lib/verify.js:6:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (/usr/local/lib/node_modules/sol-verifier/bin/sol-verifier.js:5:20)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

๐Ÿ’ป Environment
npm version - 3.5.2
node version - 8.10.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.