このページは英語からの機械翻訳を使用しており、誤りや不明瞭な表現が含まれている可能性があります。最も正確な情報については、オリジナルの英語版をご覧 ください。頻繁な更新のため、一部のコンテンツはオリジナルの英語になっている可能性があります。Crowdinでの取り組みに参加して、このページの翻訳改善にご協力ください。 (Crowdin translation page, Contributing guide)
How to Verify Smart Contracts Using Foundry
This guide walks you through the steps to automatically verify your smart contract’s source code on Kaiascan directly from your CLI using Foundry. At the moment, Kaiascan only supports the verification of flattened contract files when using Foundry.
Ensure that your contract is flattened before proceeding with the verification process.
Getting started
This guide expects that you have an idea of developing smart contracts with Foundry. See Deploy smart contract using Foundry to get started. We are going to be deploying and verifying this sample NFT contract below:
// SPDX-License-Identifier: UNLICENSEDpragma solidity >=0.8.10;import { ERC721 } from "solmate/tokens/ERC721.sol";import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";error MintPriceNotPaid();error MaxSupply();error NonExistentTokenURI();error WithdrawTransfer();contract NFT is ERC721, Ownable { using Strings for uint256; string public baseURI; uint256 public currentTokenId; uint256 public constant TOTAL_SUPPLY = 10_000; uint256 public constant MINT_PRICE = 0.08 ether; constructor( string memory _name, string memory _symbol, string memory _baseURI ) ERC721(_name, _symbol) Ownable(msg.sender) { baseURI = _baseURI; } function mintTo(address recipient) public payable returns (uint256) { if (msg.value != MINT_PRICE) { revert MintPriceNotPaid(); } uint256 newTokenId = ++currentTokenId; if (newTokenId > TOTAL_SUPPLY) { revert MaxSupply(); } _safeMint(recipient, newTokenId); return newTokenId; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { if (ownerOf(tokenId) == address(0)) { revert NonExistentTokenURI(); } return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } function withdrawPayments(address payable payee) external onlyOwner { uint256 balance = address(this).balance; (bool transferTx, ) = payee.call{value: balance}(""); if (!transferTx) { revert WithdrawTransfer(); } }}
To verify a contract using Foundry verify, see the steps below:
Flatten the contract
## flattenforge flatten src/NFT.sol > FlattenedNFT.sol
Deploy the contract
## deployforge create --rpc-url $KAIROS_RPC_URL private-key $PRIVATE_KEY src/NFT.sol:NFT --broadcast --constructor-args "Kento" "KT" "https://ipfs.io/ipfs/QmdcURmN1kEEtKgnbkVJJ8hrmsSWHpZvLkRgsKKoiWvW9g?filename=simple_bull.json"
Verify the contract
## verify an already deployed contract as seen above *//forge verify-contract --verifier-url https://kairos-api.kaiascan.io/forge-verify-flatten --chain-id 1001 --constructor-args $(cast abi-encode "constructor(string,string,string)" "Kento" "KT" "https://ipfs.io/ipfs/QmdcURmN1kEEtKgnbkVJJ8hrmsSWHpZvLkRgsKKoiWvW9g?filename=simple_bull.json") --compiler-version v0.8.26+commit.8a97fa7a 0x06F09d3f77341B2f9bDC1E6fc2928761ba05f934 FlattenedNFT.sol:NFT --retries 1
You can look up the verified contract here