There are currently two methods to verify your code on OKLink. You can either use the recommended @okxweb3/hardhat-explorer-verify plugin, or modify the hardhat.config.js
file according to Hardhat's official documentation.
npm install @okxweb3/hardhat-explorer-verify
import "@nomicfoundation/hardhat-toolbox";
import '@okxweb3/hardhat-explorer-verify'; // Import the plugin
const config: HardhatUserConfig = {
solidity: "0.8.20",
sourcify: {
enabled: true,
},
networks: {
xlayer: {
url: "https://xlayerrpc.example.com",
accounts: ["<Your Wallet Private Key>"],
},
},
etherscan: {
apiKey: '...'
},
okxweb3explorer: {
apiKey: "<Your API Key>",
}
};
export default config;
npx hardhat okverify --network xlayer <Your Contract Address>
An example command:
npx hardhat okxverify --network xlayer --contract <Contract>:<Name> --proxy <address>
--proxy
refers to the proxy contract address.--proxy
. Instead, replace it with --contract
.hardhat.config.js
file in your project directory with the following changes.
For X Layer testnet or mainnet:module.exports = {
solidity: "0.8.9",
networks: {
xlayer: {
url: "https://testrpc.xlayer.tech", //or https://rpc.xlayer.tech for mainnet
accounts: [process.env.PRIVKEY]
}
},
etherscan: {
apiKey: process.env.ETHERSCAN_KEY,
customChains: [
{
network: "xlayer",
chainId: 195, //196 for mainnet
urls: {
apiURL: "https://www.oklink.com/api/v5/explorer/contract/verify-source-code-plugin/XLAYER_TESTNET", //or https://www.oklink.com/api/v5/explorer/contract/verify-source-code-plugin/XLAYER for mainnet
browserURL: "https://www.oklink.com/xlayer-test" //or https://www.oklink.com/xlayer for mainnet
}
}
]
}
};
Replace process.env.PRIVKEY
with your own deployment address’s private key, and process.env.ETHERSCAN_KEY
can be filled with your OKLink API Key, which can be applied from [My account - API management] on https://www.oklink.com/ for free
hh run scripts/deploy.js --network xlayer
hh verify --contract contracts/Lock.sol:Lock <address> <unlock time> --network xlayer