hardhat-zksync-solc
hardhat-zksync-solc
这个插件用于在将Solidity智能合约部署到zkSync Era之前提供一个方便的接口来编译它们。
安装
@matterlabs/hardhat-zksync-solc
用以下命令将该插件的最新版本添加到你的项目中。
# Yarn
yarn add -D @matterlabs/hardhat-zksync-solc
# Npm
npm i -D @matterlabs/hardhat-zksync-solc
Exports
这个插件大多数时候不会直接在代码中使用。
Configuration
这个插件是在你的项目的hardhat.config.ts
文件中配置的。下面是一个例子
zksolc: {
version: "1.3.1",
compilerSource: "binary", // binary or docker (deprecated)
settings: {
compilerPath: "zksolc", // ignored for compilerSource: "docker"
experimental: {
dockerImage: "matterlabs/zksolc", // Deprecated: used for compilerSource: "docker"
tag: "latest" // Deprecated: used for compilerSource: "docker"
},
libraries:{}, // optional. References to non-inlinable libraries
isSystem: false, // optional. Enables Yul instructions available only for zkSync system contracts and libraries
forceEvmla: false // optional. Falls back to EVM legacy assembly if there is a bug with Yul
}
}
networks: {
hardhat: {
zksync: true // enables zksync in hardhat local network
}
}
Note
编译器不再作为Docker镜像发布,不再推荐使用。使用Hardhat配置文件中的 compilerSource: "binary"
在Hardhat配置文件中使用二进制文件来代替。
version
is a field with the version of thezksolc
compiler. Compiler versions can be found in the following repository.compilerSource
indicates the compiler source and can be eitherdocker
orbinary
(recommended). If there isn't a compiler binary already installed, the plugin will automatically download it. Ifdocker
is used, you'd need to run Docker desktop in the background and provide bothdockerImage
andtag
in the experimental section.compilerPath
(optional) is a field with the path to thezksolc
binary. By default, the binary in$PATH
is used. IfcompilerSource
isdocker
, this field is ignored.dockerImage
andtag
make up the name of the compiler docker image. IfcompilerSource
isbinary
, these fields are ignored.libraries
if your contract uses non-inlinable libraries as dependencies, they have to be defined here. Learn more about compiling libraries hereisSystem
- required if contracts use enables Yul instructions available only for zkSync system contracts and librariesforceEvmla
- falls back to EVM legacy assembly if there is a bug with Yulzksync
network option indicates whether zksolc is enabled on a certain network.false
by default. Useful for multichain projects in which you can enablezksync
only for specific networks.
`forceEvmla` usage
将 "forceEvmla "字段设置为 "true "会产生以下负面影响。
- 不支持递归。
- 不支持内部函数指针。
- 合同大小或性能影响。
对于0.8以前的solidity版本,该设置在编译时是默认执行的。
Commands
hardhat compile
-- 编译contracts
目录下的所有智能合约,并创建artifacts-zk
文件夹,其中包含所有编译工件,包括合约的工厂依赖,可用于合约部署。
要了解什么是工厂依赖,请阅读Web3 API文档中的更多内容。