ERC3156 项目教程
1. 项目的目录结构及介绍
ERC3156/
├── contracts/
│ ├── ERC3156FlashBorrower.sol
│ ├── ERC3156FlashLender.sol
│ ├── IERC3156FlashBorrower.sol
│ ├── IERC3156FlashLender.sol
│ └── ...
├── test/
│ ├── ERC3156FlashBorrower.test.js
│ ├── ERC3156FlashLender.test.js
│ └── ...
├── scripts/
│ ├── deploy.js
│ └── ...
├── package.json
├── README.md
└── ...
目录结构介绍
- contracts/: 包含所有智能合约文件,如
ERC3156FlashBorrower.sol
和ERC3156FlashLender.sol
。 - test/: 包含项目的测试文件,如
ERC3156FlashBorrower.test.js
和ERC3156FlashLender.test.js
。 - scripts/: 包含部署脚本和其他辅助脚本,如
deploy.js
。 - package.json: 项目的依赖管理文件。
- README.md: 项目的介绍和使用说明。
2. 项目的启动文件介绍
项目的启动文件主要是 scripts/deploy.js
,该文件用于部署智能合约到区块链网络。
scripts/deploy.js
const hre = require("hardhat");
async function main() {
const ERC3156FlashLender = await hre.ethers.getContractFactory("ERC3156FlashLender");
const lender = await ERC3156FlashLender.deploy();
await lender.deployed();
console.log("ERC3156FlashLender deployed to:", lender.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
启动步骤
- 安装依赖:
npm install
- 编译合约:
npx hardhat compile
- 部署合约:
npx hardhat run scripts/deploy.js --network <network>
3. 项目的配置文件介绍
package.json
{
"name": "ERC3156",
"version": "1.0.0",
"description": "Reference implementations for ERC20 Flash Loans and Flash Mints",
"main": "index.js",
"scripts": {
"test": "npx hardhat test",
"deploy": "npx hardhat run scripts/deploy.js --network <network>"
},
"author": "Alberto Cuesta Cañada",
"license": "GPL-3.0",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"chai": "^4.3.4",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.1",
"hardhat": "^2.4.1"
}
}
配置文件介绍
- name: 项目名称。
- version: 项目版本。
- description: 项目描述。
- scripts: 包含项目的脚本命令,如测试和部署。
- devDependencies: 开发依赖包,如
hardhat
和ethers
。
通过以上步骤,您可以成功部署和使用 ERC3156 项目。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考