Links

Smart Contract Verification

Important: You MUST deploy and verify with the SAME source code. So, DO NOT CHANGE ANYTHING OF CONTRACTS. If you change, the byte codes are different and verify smart contract never passes.

Verify with Hardhat

1. Setup Hardhat config

import { HardhatUserConfig, task } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "./scripts/deploy"; // import script verify
​
​
const privateKey = '<ADD_YOUR_PRIVATE_KEY_HERE>'
const apiKeyEthereum = '<YOUR_API_KEY>' // you can get api key from etherscan.io or bscscan.com
const config: HardhatUserConfig = {
solidity: "0.8.9",
networks: {
posichain_testnet: {
url: "http://api.s0.t.posichain.org",
chainId: 910000,
accounts: [privateKey]
},
posichain_mainnet: {
url: "https://api.posichain.org/",
chainId: 900000,
accounts: [privateKey]
​
}
},
etherscan: {
apiKey: apiKeyEthereum,
customChains: [
{
network: "posichain_testnet",
chainId: 910000,
urls: {
apiURL: "https://apex-testnet.posichain.org/contract-verifier/verify", // the api to verify
browserURL: "https://explorer-testnet.posichain.org/"
}
},
{
network: "posichain_mainnet",
chainId: 900000,
urls: {
apiURL: "https://apex.posichain.org/contract-verifier/verify",
browserURL: "https://explorer.posichain.org/"
}
},
]
}
};
​
export default config;
​

2. Write script verify contract

import {task} from "hardhat/config";
​
export async function verifyContract(
hre : any,
address : string,
args : undefined,
contract : string | undefined
) {
const verifyObj = { address } as any;
if (args) {
verifyObj.constructorArguments = args;
}
if (contract) {
verifyObj.contract = contract;
}
return hre
.run("verify:verify", verifyObj)
.then(() => console.log("Contract address verified:", address))
.catch((err : any) => {
console.log(`Verify Error`, err);
});
}
​
​
task("verify", "verify", async (taskArgs, hre) => {
const contractAddress = 'YOUR_CONTRACT_ADDRESS';
const args : any= [];// The list arguments of contract
const contractProvider = 'YOUR_PATH_CONTRACT' // Example:"contracts/HelloPosiChain.sol:HelloPosiChain"
await verifyContract(
hre,
contractAddress,
args,
contractProvider);
});

3. Run script verify

npx hardhat <YOUR_TASK> --network <YOUR_NETWORK>
Example command:
npx hardhat verify --network posichain_mainnet

Verify with Explorer

1. Flatten your Solidity Files

To flatten your solidity files we recommended to use Truffle Flattener lib.npm install truffle-flattener -gtruffle-flattener <solidity-files>Or you can use any other flattener lib.

2. Deploy Contract to POSI Chain

To easier the verification we recommend the contract deployment using Ethereum Remix.

3. Verify Contract

You can verify your contract here: ​ https://explorer.posichain.org/verifycontract​
Verify Contract
It is important to use the correct parameters (same as on deployment):
  • Contract address
  • Contract name
  • Compiler version
  • Optimizer
  • Chain Type (mainnet or testnet)
  • Sources
  • Imported libs
Then click on Sumbit button. If all params was correct - you will see Success message, or Error if bytecodes are not equal. On the Success case - your contract will verify and you will see all contract details on contract explorer page.