M1 Mac install node
# 首先安装mvn
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
# 安装后可能会提示你设置环境变量,按照提示运行去设置即可
# 如果网络无法连接,可能需要export一下proxy
# 然后用nvm安装node
nvm install 14.18.2
# 然后启用刚安装的版本
nvm use node
# 查看版本
node -v
# 首先安装mvn
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
# 安装后可能会提示你设置环境变量,按照提示运行去设置即可
# 如果网络无法连接,可能需要export一下proxy
# 然后用nvm安装node
nvm install 14.18.2
# 然后启用刚安装的版本
nvm use node
# 查看版本
node -v
注意:名字不一定是KeyboardLayout Name U.S.,可以根据自己情况删除
引入@openzeppelin/test-helpers
const { ether, BN, expectRevert, expectEvent, constants, time, balance, send } = require('@openzeppelin/test-helpers');
npm install -g truffle-flattener
because some new features in solidity 0.8.x might go wrong by [email protected], so after installed, run code below again:
inpm nstall -g https://github.com/jplew/truffle-flattener
usage:
truffle-flattener ./contracts/MyContract.sol > ./flatten/MyContractFlatten.sol
and then put faltten code as single solidity file to bscscan
npm init -y
it will generate a file package.json in the root folder
npm install @openzeppelin/contracts
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC20, Ownable {
constructor() ERC20("MyToken", "MTK") {}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
more usage, see node_modules/@openzeppelin/contracts/README.md
note: pragma solidity in the MyToken.sol above is ^0.8.4, and it is 0.8.0 in "@openzeppelin/contracts/token/ERC20/ERC20.sol", but it also compile successful
truffle compile
more details, watch this: /playlist?list=PLbbtODcOYIoFdQ37ydykQNO-MNGER6mtd