hardhat.config
require('@nomiclabs/hardhat-ethers');
require('dotenv').config();
const { BSC_API_URL, MNEMONIC } = process.env;
module.exports = {
solidity: "0.5.16",
networks: {
bsc: {
url: BSC_API_URL,
accounts: {
mnemonic: MNEMONIC,
},
},
hardhat: {
forking: {
url: BSC_API_URL,
},
},
},
};
脚本/deploy.js
const { ethers } = require("hardhat");
async function main() {
const [deployer] = await ethers.getSigners();
const PancakeFactory = await ethers.getContractFactory('PancakeFactory');
const factory = await PancakeFactory.deploy(deployer.address);
await factory.deployed();
console.log('PancakeFactory deployed to:', factory.address);
const PancakePair = await ethers.getContractFactory('PancakePair');
const pair = await PancakePair.deploy();
await pair.deployed();
console.log('PancakePair deployed to:', pair.address);
console.log(`PancakeFactory Address: ${factory.address}`);
console.log(`PancakePair Address: ${pair.address}`);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
运行 npx Hardhat 编译后,我收到错误
PS D:ask\pancake-swap-core\scripts> npx Hardhat 编译 错误 HH8:您的配置文件中存在一个或多个错误:
要了解有关 Hardhat 配置的更多信息,请访问 https://hardhat.org/config/
我如何成功将 pancake swap v2 分叉到 bsc?
问题是无法从
.env
文件中读取变量。
您是否已在
Hardhat项目的 root 目录中创建了
.env
文件?
在 .env 文件中,您需要从 here
添加 bsc-test 的 rpc url您还需要一个帐户助记词,您可以从 Metamask 等钱包中获取该助记词。这是获取秘密短语的链接。我为您添加了一个示例助记词。
BSC_API_URL=https://data-seed-prebsc-1-s1.binance.org:8545/
MNEMONIC=carpet cat flower chair foot river make image amazing three say shoe
将值添加到 .env 文件中的变量后,尝试再次编译合约。应该可以。