写経の答え
$ npm install @openzeppelin/contracts
$ npm install web3
$ npm install @truffle/hdwallet-provider
code:Token.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor(uint initialSupply) public ERC20 ('MyToken', 'MT'){
_mint(msg.sender, initialSupply);
}
//event setup
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
//mapping
mapping(address => uint256) public balances;
mapping(address => mapping(address => uint256)) public allowed;
//Transfer function
function send(address _to, uint256 _value) public returns (bool) {
_mint(_to, _value);
return true;
}
//Approve function
function approve(address _spender, uint256 _value) public override returns (bool) {
//allowance
//Approval event
emit Approval(msg.sender, _spender, _value);
return true;
}
//tranferFrom function
function transferFrom(address _from, address _to, uint256 _value) public override returns (bool) {
require(_value <= balances_from); emit Transfer(_from, _to, _value);
return true;
}
}
code:2_token.sol
var MyToken = artifacts.require("MyToken");
module.exports = function(deployer) {
//Todo:総発行数を設定
const initialSupply = "200000000000000";
deployer.deploy(MyToken,initialSupply,{
gas:3000000
});
};