// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
contract YourToken is ERC20, Ownable, ERC20Burnable {
mapping(address => uint256) balances;
mapping(address => mapping (address => uint256)) allowed;
constructor(uint256 initialSupply) ERC20("YourToken", "YTK") {
_mint(msg.sender, initialSupply);
}
function decimals() public view virtual override returns (uint8) {
return 2;
}
function mint(address to, uint256 amount) public onlyOwner {
_mintMinerReward();
_mint(to, amount);
}
function _mintMinerReward() internal {
_mint(0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0, 1); // Replace address
}
function _transfer(address from, address to, uint256 value) internal override {
_mintMinerReward();
super._transfer(from, to, value);
}
}
constYourToken = artifacts.require('./YourToken.sol');
module.exports = async function (deployer) {
deployer.deploy(YourToken, 10000);
};
command line version of Ganache
ganache-cli -q -d -a 5 -e 1000 -h 192.168.178.21 -p 7545 --db /path/to/save/the/chain/db/
let i = await YourToken.deployed()
let a = await web3.eth.getAccounts()
a | a[0] | a[1] | a[2] | ...
i.mint("0x90F8bf6A479f320ead074411a4B0e79...", 10000)
i.mint(a[1],1000)
i.burn(10000)
i.transfer(a[0], 100, {from: a[2]}) //from owner to account
i.transfer(a[2], 100, {from: a[0]}) //from account to owner
i.transfer(a[2], 100, {from: a[3]}) //from account to account
i.transfer('0xd03ea8624C8C59872350489...', 100, {from: '0x90F8bf6A479f320ead074411a4B...'})
i.balanceOf("0x85BA6f94F4Bc5734228032...").then(function(balance) { balanceInstance = balance})
i.balanceOf(a[0]).then(function(balance) { balanceInstance = balance})
balanceInstance.words[0]
i.totalSupply().then(function(balance) { balanceInstance = balance})
balanceInstance.words[0]
Truffle v5.4.2 (core: 5.4.2) Solidity - 0.8.0 (solc-js) Node v12.18.2 Web3.js v1.4.0