Created
March 28, 2022 14:07
-
-
Save mikkipastel/82e5dceb2cac26eefca1dab079c76b7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [1] ประกาศ solidity ว่าใช้ version อะไร | |
pragma solidity ^0.8.7; | |
// [2] import smart contract อื่นเข้ามา ซึ่งอันนี้ไม่ต้องก็ได้ เผื่อใช้ 3rd-party | |
////import "openzeppelin-contracts/token/ERC20/ERC20.sol"; | |
////import "openzeppelin-contracts/access/Ownable.sol"; | |
// [3] ชื่อของ smart contract ในที่นี้ชื่อ Token | |
// และ inherit สืบทอดคุณสมบัติต่างๆของ smart contract อะไร ในที่นี้คือ ERC20 และ Ownable ใส่หลัง is | |
contract Token is ERC20, Ownable { | |
// [4] ประกาศตัวแปรเบื้องต้น ที่ constructor | |
constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {} | |
// [5] function นี้ชื่ออะไร รับ parameter อะไร แล้วข้างในทำอะไร | |
// ผลลัพธ์เป็นเหมือนเดิมตลอด ทำงานภายใต้สมการทางคณิตศาสตร์ทั้งหมด | |
function mint(address recipient, uint256 amount) external onlyOwner { | |
require(amount > 0, "amount must greater than 0"); | |
require(recipient != address(0), "invalid recipient"); | |
super._mint(recipient, amount * 10 ** 18); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment