我想在我的测试中使用node_modules中的一个契约,但是我得到了:HardhatError: HH700: Artifact for contract "SomeContract" not found.
这可能是因为/contracts目录下的任何文件都不使用它,因此不会生成工件。有办法在node_module中编译这些合同吗?
发布于 2021-11-26 14:07:05
有两种解决办法。
这就是我在我的个人合同库里做的
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;
import "@prb/math/contracts/PRBMathUD60x18.sol";正如您所看到的,所有这些都是从npm包中导入外部契约,这样的话,硬件就会捡起它并为它生成一个工件。
这是一个由尼克巴里开发的安全帽插件。安装:
yarn add --dev hardhat-dependency-compiler并将以下内容添加到您的硬帽子配置文件中:
dependencyCompiler: {
paths: [
'path/to/external/Contract.sol',
],
}不管它有什么价值,我更喜欢第一个解决方案。它不那么冗长,因为我没有在我的package.json文件中添加另一个节点包。
发布于 2022-10-05 22:06:28
如果您的node_modules中的契约已经包含已编译的输出(即abi和字节码),那么您可以将这些已编译的输出文件设置为测试文件中的变量,并在通过ethers方法设置契约对象时将abi和字节码作为参数传递。
例如,在使用npm包@ensdomains/ens-contracts时,我已经这样做了:
const { expect } = require('chai');
const { ethers } = require('hardhat');
const ensRegistryCompiled = requires('@ensdomains/ens-contracts/artifacts/contracts/registry/ENSRegistry.sol/ENSRegistry.json');
describe('test', () => {
before(async () => {
[deployer] = await ethers.getSigners();
const ENSRegistryFactory = await ethers.getContractFactory(ensRegistryCompiled.abi, ensRegistryCompiled.bytecode);
const ENSRegistry = await ENSRegistryFactory.deploy();
await ENSRegistry.deployed();
/// rest of your test filehttps://ethereum.stackexchange.com/questions/114376
复制相似问题