#鐵人賽 #ethereum #solidity
今天開始來實作 ERC20 吧!
本日實作的函式:
本日影片: https://youtu.be/N_ooNW0NgVo
本日合約:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
interface IERC20 {
//event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
//function totalSupply() external view returns (uint256);
//function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
//function transfer(address to, uint256 amount) external returns (bool);
//function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
contract ERC20 is IERC20 {
mapping(address => mapping(address => uint256)) _allowance;
function allowance(address owner, address spender) public view returns (uint256) {
return _allowance[owner][spender];
}
function approve(address spender, uint256 amount) public returns (bool) {
_allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
}
本影片提到的連結:
「Remix IDE」: https://remix.ethereum.org/
「在 2022 年,我們該如何寫智能合約」: https://ithelp.ithome.com.tw/users/20083367/ironman/5019
「那些關於 Ethereum 的事」: https://ithelp.ithome.com.tw/users/20083367/ironman/5136
「一本關於 Ethereum 與 Solidity 智能合約的書」: https://solidity.tw
「文章或主題許願池」: https://github.com/hydai/solidity-book/issues
「本系列播放清單」: https://www.youtube.com/playlist?list=PLHmOMPRfmOxQYDnXAc1hKY6ra4WDU8ZlM