俗話說有借有還,有發行新 Token 的數量,就有燒毀來減少 Token 的數量。於是今天就來告訴大家怎麼把發出來的 Token 給燒掉XD
本日合約:
pragma solidity ^0.4.25;
import "browser/ERC20.sol";
contract Burnable is ERC20 {
event Burn(address account, uint256 tokens);
function burn(uint256 tokens) public returns (bool) {
// 檢查夠不夠燒
require(tokens <= _balances[msg.sender]);
// 減少 total supply
_totalSupply = _totalSupply.sub(tokens);
// 減少 msg.sender balance
_balances[msg.sender] = _balances[msg.sender].sub(tokens);
emit Burn(msg.sender, tokens);
emit Transfer(msg.sender, address(0), tokens);
return true;
}
}
本日影片:
https://youtu.be/5iunuADxlSU
Smart Contract 實戰教學播放清單:
https://www.youtube.com/playlist?list=PLHmOMPRfmOxSJcrlwyandWYiuP9ZAMYoF