FVM, Starboard, FVM Explorer, Block Explorer, FVM Dashboard, Filecoin Virtual Machine, Filecoin, Smart Contract, Decentralized Storage, FEVM

 Verify your contract with us!  Click here

Latest Block0Base Fee0 attoFIL/Gas Unit

Verifying Smart Contracts with API

1. Preparing Files and Information

To verify smart contracts with API, you will need to prepare the following:

  • The metadata.json file. (See FAQ: How do I obtain the metadata file?)
  • All required solidity files listed in the metadata.json file, including import files. If you want to verify using a single file, you can flatten your smart contracts. (See FAQ: Which files should I prepare along with the metadata.json file(s)?)
  • The Ethereum/Filecoin address of your smart contract.

2. Calling the API

Network

  • Mainnet: https://fvm-api.starboard.ventures
  • Calibraction: https://fvm-calibration-api.starboard.ventures

Request

Here is an example of a cURL request:

curl --request POST '${Network}/api/v1/contract/${YourContractAddress}/verify'   
--form 'metadata.json=@"path/metadata.json"'   
--form 'xxx.sol=@"path/xxx.sol"'   
--form 'hardhat/console.sol=@"path/console.sol"'   
--form '@openzeppelin/contracts/token/ERC721/ERC721.sol=@"path/@openzeppelin/contracts/token/ERC721/ERC721.sol"'  

The HTTP Form Key must include:

  • metadata.json
  • Relative path of the contract source code. (See FAQ: Why do I need metadata.json? - bullet 3)

Response

When you make a request, you will get a response like this:

{
    "request_id": "807410cd-217e-43dc-9cef-8b2b76f5e743#5553331",
    "code": 4,
    "message": "missingfile:contracts/xxxxxxxxx.sol"
}

If the code is equal to 0, it means the contract was verified successfully. If not, you can get the error details and missing information from the message field.

3. Limitations

The current system has not yet been optimized for memory usage. Please refrain from using concurrent calls to the verify API.

4. FAQ

Why do I need metadata.json?

The metadata.json file contains information about the compiled smart contract.

  • Compiler parameters
    • Compiler version: compiler.version
    • Compiler optimization switch: settings.optimizer.enabled, settings.optimizer.runs
    • Virtual machine version: settings.evmVersion
  • The contract to be deployed: A Solidity file may contain multiple contracts. When deploying to the blockchain, the developer needs to explicitly specify which contract to deploy. Similarly, when verifying, the developer needs to specify which contract to verify. If not specified, all contracts need to be enumerated to handle.
    • Target contract for deployment (contract to be verified):
      • compilationTarget.${solidity file name}: ${contract name}
  • Contract source code: The relative or absolute path needs to be configured correctly during compilation, so the contract path needs to be specified. metadata.json contains the relative path in the project.
    • Contract to be compiled and its relative path: sources -> ${relative path/solidity file name}

Read more about metadata: https://docs.soliditylang.org/en/latest/metadata.html

 

Why not verify my contracts with functions like compileSingle, compileMulti?

  • Reference: https://github.com/ethereum/solc-js#low-level-api

  • These low-level functions remain available for compatibility reasons. However, they were superseded by the compile() function and are no longer required. Starting from version 0.5.0+commit.1d4f565a, the functions compileSingle, compileMulti, and compileCallback are always null when using newer solc binary versions. It is recommended to use the latest release of solc-js, but it should also handle all the older solc binaries down to 0.1.x.

 

How do I obtain the metadata file?

  • Using the Remix Integrated Development Environment (IDE):

    You can find the metadata.json file in File explorer -> contracts -> artifacts -> ${contract_name}_metadata.json.

  • Using the Solidity Compiler (solc):

    To generate the metadata file using the solc compiler, execute the following command:

    solc --metadata --bin-runtime -o ./artifacts MyContract.sol
    

    This command compiles the 'MyContract.sol' smart contract file, producing the metadata file in the './artifacts' directory with the naming convention 'xxx.json'. Once generated, submit this metadata file to the specified interface for contract verification.

    You can read more on obtaining metadata files at Sourcify Documentation.

 

Which files should I prepare along with the metadata.json file(s)?

  • The metadata.json file includes a list of required files to be uploaded for contract verification. To ensure a successful verification process, submit all the files referenced in the metadata.json file via the API. The number of .sol files required depends on the configuration provided in the metadata. Any missing files will show up in the return message.

  • If your .sol file contains imported external files, it is essential to locate and submit these files for accurate contract verification. For instance, when using Remix IDE, press and hold the 'Alt' key while clicking on the imported file to access the external file. After accessing the file, save it. Please ensure that you do not introduce any additional characters while saving, such as new lines at the end of the file, or permit the IDE to auto-format the content.

© 2023 Starboard. Disclaimer: Information displayed externally reported figures, for which Starboard assumes no liability. Report Issues.