Verify & Publish Contract Source Code

In web3 development, the smart contract runs as a program on the blockchain and its source code is publicly available to anyone. Source code verification guarantees that a smart contract’s source code files match the assembly code, therefore, the security of users’ transactions could be assured.

In Rangers Protocol, developers can conduct the smart contract verification process by entering Rangers Scan Verify.

Note:

Blockchains under the Rangers Protocol ecosystem only support smart contracts that are coded with Solidity programming language.

Verification of a Single Solidity File

  1. The developer needs to deploy the smart contract first before beginning the verification procedure. Navigate to Remix IDE and establish a new file with the name "exampleModifier.sol". Paste the subsequent code:

    // SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract exampleModifier {
    address public owner;
    uint public account;

    constructor(){
        owner = msg.sender;
        account = 0;
    }

    modifier onlyOwner(uint _account){
        require(msg.sender == owner, "Only Owner");
        require(_account > 100, "Valid 100");
        _;
    }

    function updateAccount(uint _account) public onlyOwner(_account){
        account = _account; 
    }
}
  1. It is essential for the developers to take notes of the Solidity compiler version and the license information for the contract above, which is available at the head of the file as "SPDX-License-Identifier".

  1. Start the verification process by entering Rangers Scan Verify.

    • Input the smart contract address, which would be checked by Rangers Scan after the contract is deployed.

    • Select the “Solidity (Single file)” and the corresponding compiler version number.

    • Click the “Continue” button and proceed to the next step.

  1. Fill in the following fields:

    • Contract Address (required)

    • Compiler Version Number (required)

    • Solidity Contract Code (required)

    • Enabled Optimizer (default false): must be consistent with the file compilation parameters

    • Runs (Optimizer, default 200): (Applicable when Optimization = Yes) Optimize for the number of times you intend to run the code. A lower value will optimize more for initial deployment cost, a higher value will optimize more for high-frequency usage.

    • EVM Version to target (default compilers): When you compile your contract code you can specify the Ethereum virtual machine version to compile to avoid particular features or behaviors.

  1. Click the “Verify and Publish” button and proceed to the next step.

  1. Now the smart contract and source code are verified and public to other developers.

  1. Once you meet the error situation or warnings, please check the below reference for your information.

    • Common Error Types for Compiling

      • JSONError: JSON input does not match the required format, e.g. input is not a JSON object, language is not supported, etc.

      • IOError: IO and import processing errors, such as unresolvable URLs or hash mismatches in the provided source

      • ParserError: Source code does not match the language rules

      • DocstringParsingError: Unable to parse NatSpec tag in the comment block

      • SyntaxErrorcontinuefor: Syntax error, e.g. used outside of a loop

      • DeclarationErrorIdentifier not found: Invalid, unresolvable, or conflicting identifier name

      • TypeError: Errors within the type system, such as invalid type conversions, invalid assignments, etc.

      • UnimplementedFeatureError: The compiler does not support this feature

      • InternalCompilerError: Internal error triggered in the compiler

      • Exception: Unknown fault during compilation

      • CompilerError: Compiler stack use is invalid

      • FatalError: Error not handled correctly

    • Common Error Types for Submission

      • A contract address is required

      • Invalid Length

      • Please provide a valid Contract Address

      • InvalId_Field

      • Incomplete Input

Verification of Multi-Parts Solidity Files

  1. Rangers Scan Verify also considers the complex scenario in that one smart contract calls multiple smart contracts for running smoothly.

  2. As mentioned above, developers need to deploy the smart contract first before beginning the verification procedure.

  3. If you need to verify more than one smart contract at once, select “Solidity (Multi-Part files)”.

  1. Start the verification process by entering Rangers Scan Verify.

    • Input the smart contract addresses, which would be checked by Rangers Scan after the contracts are deployed.

    • Select “Solidity (Single file)” and the corresponding compiler version number.

    • Click the “Continue” button and proceed to the next step.

  2. Click the “Verify and Publish” button and proceed to the next step.

  1. Now the smart contracts and source code are verified and open to the public.

  1. Once you meet the error situation or warnings, please check the below reference for your information.

    • Common Error Types for Compiling

      • JSONError: JSON input does not match the required format, e.g. input is not a JSON object, language is not supported, etc.

      • IOError: IO and import processing errors, such as unresolvable URLs or hash mismatches in the provided source

      • ParserError: Source code does not match the language rules

      • DocstringParsingError: Unable to parse NatSpec tag in the comment block

      • SyntaxErrorcontinuefor: Syntax error, e.g. used outside of a loop

      • DeclarationErrorIdentifier not found: Invalid, unresolvable, or conflicting identifier name

      • TypeError: Errors within the type system, such as invalid type conversions, invalid assignments, etc.

      • UnimplementedFeatureError: The compiler does not support this feature

      • InternalCompilerError: Internal error triggered in the compiler

      • Exception: Unknown fault during compilation

      • CompilerError: Compiler stack use is invalid

      • FatalError: Error not handled correctly

    • Common Error Types for Submission

      • A contract address is required

      • Invalid Length

      • Please provide a valid Contract Address

      • InvalId_Field

      • Incomplete Input

Last updated