安装环境
- 下载代码编译环境 官方帮助文档 hardhat-zksync-solc | Welcome to our Docs | zkSync Era
https://github.com/matter-labs/hardhat-zksync
VCode 软件打开要目录
yarn install
合约代码复制到目录
找到文件修改网络文件 examples\basic-example\hardhat.config.ts
networks: {
hardhat: {
zksync: true,
},
// goerli: {
// url: "https://goerli.infura.io/v3/<API Key>" // The Ethereum Web3 RPC URL (optional).
// },
zkTestnet: {
url: "https://testnet.era.zksync.dev", // The testnet RPC URL of zkSync Era network.
ethNetwork: "goerli", // The Ethereum Web3 RPC URL, or the identifier of the network (e.g. `mainnet` or `goerli`)
zksync: true
}
},
进入目录编译
cd examples
cd basic-example
yarn hardhat compile
yarn build
找到编译后的文件位置
找到 bytecode
找到ABI JSON
到些已经完成bytecode和ABI
合约验证官方文档 hardhat-zksync-verify | Welcome to our Docs | zkSync Era
添加依赖
yarn add -D @matterlabs/hardhat-zksync-verify @nomiclabs/hardhat-etherscan
Configuration
Import the plugin in the hardhat.config.ts file
import "@matterlabs/hardhat-zksync-verify";
添加网络验证URL
networks: {
goerli: {
url: "https://goerli.infura.io/v3/<API_KEY>" // The Ethereum Web3 RPC URL (optional).
},
zkTestnet: {
url: "https://testnet.era.zksync.dev", // The testnet RPC URL of zkSync Era network.
ethNetwork: "goerli", // The Ethereum Web3 RPC URL, or the identifier of the network (e.g. `mainnet` or `goerli`)
zksync: true,
// Verification endpoint for Goerli
verifyURL: 'https://zksync2-testnet-explorer.zksync.dev/contract_verification'
}
},
// defaultNetwork: "zkTestnet", // optional (if not set, use '--network zkTestnet')
执行
yarn hardhat verify --network <网络> <合约地址>
yarn hardhat verify --network zkTestnet 0xe922B1760474727305B44A73f3bA62c669Fec672
成功