Skip to main content
Time to read: 1 min

Verify Smart Contract on Rootstock-CLI

To verify a smart contract on the Rootstock-CLI, the rsk-cli verify command allows developers to submit their contract source code and other information to the Rootstock Explorer API.

The rsk-cli verify command enables the verification of a smart contract on Rootstock's mainnet or testnet by providing the contract code, address, and other metadata through a JSON file.

Smart Contract Verification on Rootstock's blockchain allows users to confirm that the compiled bytecode on the blockchain matches the source code.

rsk-cli verify --json <path_to_json> --address <address> --name <contract_name> --decodedArgs <arg1> <arg2> ...
info

  1. --json \<path\_to\_json\>
  • This specifies the path to the JSON file that contains all necessary information for verifying the contract. The JSON file should typically contain:
    • Source code of the contract.
    • Compiler version and settings.
    • ABI (Application Binary Interface) data for interacting with the contract.
    • Metadata for libraries if the contract has dependencies.
  • Example: If your JSON file is named fb7b3667b850d874bffe750e005d2477.json and it is usually in the build-info folder under the artifacts folder, you would use --json .artifacts/build-info/fb7b3667b850d874bffe750e005d2477.json.
β”œβ”€β”€ artifacts
β”‚ └── build-info
β”‚ └── fb7b3667b850d874bffe750e00...
β”œβ”€β”€ contracts
β”‚ └── ContactInfo.sol
β”œβ”€β”€ cache
β”œβ”€β”€ files
β”œβ”€β”€ ignition
β”œβ”€β”€ node_modules
β”œβ”€β”€ test
β”œβ”€β”€ typechain-types
β”œβ”€β”€ .gitignore
β”œβ”€β”€ hardhat.config.ts
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ README.md
β”œβ”€β”€ rootstock-wallet.json
└── tsconfig.json
  1. --address \<address\>
    • This is the address of the deployed contract on Rootstock's blockchain (either on mainnet or testnet).
    • The address helps the Rootstock Explorer locate the specific instance of the contract you want to verify.
  • Example: --address 0x1234567890abcdef1234567890abcdef12345678.
  1. --name \<contract\_name\>
    • This is the name of the smart contract as defined in the source code.
    • This helps the verification system know which contract from the JSON file corresponds to the one deployed at the given address.
  • Example: If the contract is named ContactInfo, use --name ContactInfo.
  1. --decodedArgs \<arg1\> \<arg2\> ... (Optional)
    • decodedArgs is used when the contract’s constructor requires arguments for deployment.
    • These arguments must match the constructor parameters in the source code and are provided in a decoded format.
  • Example: If the constructor takes an address and a number, you might provide --decodedArgs 0xabcdef1234567890abcdef1234567890abcdef12 1000.
  1. --testnet (Optional)
    • This flag specifies that the contract verification should be performed on Rootstock’s testnet instead of mainnet.
    • Testnet is used for testing purposes, so developers often use it to verify contracts in a non-production environment before deploying them on the mainnet.
  • Example: If verifying on testnet, use --testnet.

To verify the same contract on the testnet:

rsk-cli verify --testnet --json artifacts/build-info/fb7b3667b850d874bffe750e005d2477.json --address 0x4edd891c2e988e6145fe3e418c652ee33ebab9ae --name ContactInfo    

With constructor arguments:

rsk-cli verify --testnet --json ./contract.json --address 0x1234567890abcdef1234567890abcdef12345678 --name MyToken --decodedArgs 0xabcdef1234567890abcdef1234567890abcdef12 1000

The response below was obtained from the command without a constructor.

πŸ”§ Initializing verification on testnet...
πŸ“„ Reading JSON Standard Input from artifacts/build-info/fb7b3667b850d874bffe750e005d2477.json...
πŸ”Ž Verifying contract ContactInfo deployed at 0x4edd891c2e988e6145fe3e418c652ee33ebab9ae..
βœ” πŸŽ‰ Contract verification request sent!
βœ” πŸ“œ Contract verified successfully!
πŸ”— View on Explorer: https://explorer.testnet.rootstock.io/address/0x4edd891c2e988e6145fe3e418c652ee33ebab9ae
Last updated on by Wisdom Nwokocha

Feedback