Create Smart Contract
source link: https://www.inevitable.tech/posts/458d64bd/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Create Smart Contract
一键搭建初始化以太坊开发环境。
这个项目有点类似 create-react-app。目的是帮助开发者快速初始化开发环境。做起来还是挺简单的。就是写一个 Node 脚本。里面包含初始化项目文件夹,安装依赖和替换模板文件。具体项目使用和介绍可以 看 Github 主页。
首先你得已经全局安装 truffle。这样 create-smart-contract myapp
,会用 truffle 为你初始化一个项目文件夹。然后为你安装一系列有用的插件和包。最后给你生成一些默认的配置文件。以下是包含的框架,插件,包和配置文件。由于目前 Openzeppelin 不支持 0.8 的 solc,所以我默认使用 0.7 的最新版。
- truffle
- [@truffle/hdwallet-provider](https://www.npmjs.com/package/@truffle/hdwallet-provider)
- eth-gas-reporter
- solidity-coverage
- truffle-assertions
- hardhat
- [ @nomiclabs/hardhat-ethers](https://www.npmjs.com/package/@nomiclabs/hardhat-ethers)
- [@nomiclabs/hardhat-truffle5](https://www.npmjs.com/package/@nomiclabs/hardhat-ethers)
- [@nomiclabs/hardhat-waffle](https://www.npmjs.com/package/@nomiclabs/hardhat-waffle)
- [@nomiclabs/hardhat-web3](https://www.npmjs.com/package/@nomiclabs/hardhat-web3)
- ethers
- [@openzeppelin/contracts](https://www.npmjs.com/package/@openzeppelin/contracts)
- chai
- solidity-docgen
- mocha
- prettier
- prettier-plugin-solidity
- solc
- web3
- ethereum-waffle
- .gitignore
- .prettierrc
- hardhat.config.js
- slither.config.json
- solcover.js
- truffle-config.js
除此之外我还加入了一些有用的 Node 脚本。
npm run test
: 用来跑测试的。我这采用了 Hardhat。因为它跑 test 的速度快,并且支持在智能合约中使用console.log
。npm run doc
: 根据 doxygen 自动生成文档。npm run coverage
: 根据配置文件.solcover.js
生成测试覆盖率报告。npm run analyze
根据配置文件slither.config.json
静态分析智能合约。注意:要求已经安装 Slither
你可以自定义想要的包。更改 index.js
的 installPackages
。例如
const installPackages = () => {
return new Promise((resolve) => {
console.log("\nInstalling hardhat\n".cyan);
shell.exec(`npm install --save-dev hardhat`, () => {
console.log("\nFinished installing packages\n".green);
resolve();
});
});
};
你可以自己更改,添加或删除模板。例如你想要添加模板,你需要将模板文件加入 templates/
然后修改 templates/templates.js
。例如
let fs = require("fs");
let path = require("path");
const gitIgnore = fs.readFileSync(path.resolve(__dirname, "./gitignore"));
const solcover = fs.readFileSync(path.resolve(__dirname, "./solcover.js"));
const slither = fs.readFileSync(
path.resolve(__dirname, "./slither.config.json")
);
const hardhatConfig = fs.readFileSync(
path.resolve(__dirname, "./hardhat.config.js")
);
const truffleConfig = fs.readFileSync(
path.resolve(__dirname, "./truffle-config.js")
);
const prettier = fs.readFileSync(path.resolve(__dirname, "./.prettierrc"));
const package = fs.readFileSync(path.resolve(__dirname, "package.json"));
const env = fs.readFileSync(path.resolve(__dirname, ".env"));
module.exports = {
".gitignore": gitIgnore,
"solcover.js": solcover,
"slither.config.json": slither,
"truffle-config.js": truffleConfig,
"hardhat.config.js": hardhatConfig,
".prettierrc": prettier,
"package.json": package,
".env": env,
};
祝你开发愉快。
Recommend
-
30
Regulation 1 min ago| By
-
20
Blockchain, ICO and Ethererum Smart Contract Development Services Like so many business ideas in the blockchain industry, a common confusion which is called 'smart contracts' . Yes….! ...
-
10
-
11
...
-
6
Prototyping generic Bitcoin Smart contract Dec 11 ・7 min read ...
-
10
Sigma Prime was commercially engaged by Dapper Labs to perform a time-boxed security review of an Ethereum smart contract wallet. This post details 3 vulnerabilities which were identified in the course of this assessment, and subsequently...
-
9
Sigma Prime was commercially engaged by Status to perform a time-boxed security review of the UsernameRegistrar smart contract, which supports the Ethereum Name Service (ENS) registrar developed by Status. This post details four vulnerabi...
-
22
The State of Smart Contract Upgrades
-
7
New Tools to Securely Manage Smart Contract Upgrades
-
5
How to Write Upgradable Smart Contracts (Smart Contract Versioning)In this post, we will understand how upgradeable smart contracts work. We will also go through practical examples using OpenZeppelin Upgrades CL...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK