ERC20代币标准怎么实现
发表于:2025-02-03 作者:千家信息网编辑
千家信息网最后更新 2025年02月03日,本篇内容介绍了"ERC20代币标准怎么实现"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!pragma
千家信息网最后更新 2025年02月03日ERC20代币标准怎么实现
本篇内容介绍了"ERC20代币标准怎么实现"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
pragma solidity ^0.4.20;// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.mdcontract NanToken { //Token //Methods //NOTE: Callers MUST handle false from returns (bool success). Callers MUST NOT assume that false is never returned! // 所有 returns (bool success) 的方法,都要考虑返回false的逻辑; //name //Returns the name of the token - e.g. "MyToken". // //OPTIONAL - This method can be used to improve usability, but interfaces and other contracts MUST NOT expect these values to be present. function name() view returns (string name); //symbol //Returns the symbol of the token.E.g. "HIX". // //OPTIONAL - This method can be used to improve usability, but interfaces and other contracts MUST NOT expect these values to be present. function symbol() view returns (string symbol); //decimals //Returns the number of decimals the token uses - e.g. 8, means to divide the token amount by 100000000 to get its user representation. // //OPTIONAL - This method can be used to improve usability, but interfaces and other contracts MUST NOT expect these values to be present. // 精度 function decimals() view returns (uint8 decimals); //totalSupply //Returns the total token supply. function totalSupply() view returns (uint256 totalSupply); //balanceOf //Returns the account balance of another account with address _owner. // 总量 function balanceOf(address _owner) view returns (uint256 balance); //transfer //Transfers _value amount of tokens to address _to, and MUST fire the Transfer event. The function SHOULD throw if the _from account balance does not have enough tokens to spend. // //Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event. // 从当前地址转指定量到指定地址 // 若当前地址没有足够的余额,应该抛出异常 // 每次调用成功,哪怕数量是0,都必须触发 Transfer 事件; function transfer(address _to, uint256 _value) returns (bool success); //transferFrom //Transfers _value amount of tokens from address _from to address _to, and MUST fire the Transfer event. // //The transferFrom method is used for a withdraw workflow, allowing contracts to transfer tokens on your behalf. This can be used for example to allow a contract to transfer tokens on your behalf and / or to charge fees in sub- currencies. The function SHOULD throw unless the _from account has deliberately authorized the sender of the message via some mechanism. // //Note Transfers of 0 values MUST be treated as normal transfers and fire the Transfer event. // 用于提币逻辑; // 每次调用成功必须触发 Transfer 事件;哪怕数量是0; function transferFrom(address _from, address _to, uint256 _value) returns (bool success); //approve //Allows _spender to withdraw from your account multiple times, up to the _value amount. If this function is called again it overwrites the current allowance with _value. // //NOTE : To prevent attack vectors like the one described here[https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh5DYKjA_jp-RLM/] and discussed here[https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729], clients SHOULD make sure to create user interfaces in such a way that they set the allowance first to 0 before setting it to another value for the same spender. THOUGH The contract itself shouldn't enforce it, to allow backwards compatibility with contracts deployed before // 允许指定的地址 分一次或多次从当前地址提币;若再次调用此方法,则重置数量 // 为避免攻击,客户端实现时应该先向某地址设置数量为0,再给相同的地址设置数量为 实际的数量; // 这为了向后兼容之前部署的合约,虽然不是强制要求 function approve(address _spender, uint256 _value) returns (bool success); //allowance //Returns the amount which _spender is still allowed to withdraw from _owner. // 查询 owner 授权给 spender 的剩余提币数量 function allowance(address _owner, address _spender) view returns (uint256 remaining); //Events //Transfer //MUST trigger when tokens are transferred, including zero value transfers. // //A token contract which creates new tokens SHOULD trigger a Transfer event with the _from address set to 0x0 when tokens are created. // token 被 成功 transfer 后,需要触发Transfer 事件,哪怕数量为0; // 当创建一个新的token后,应该触发Transfer 事件, event Transfer(address indexed _from, address indexed _to, uint256 _value); //Approval //MUST trigger on any successful call to approve(address _spender, uint256 _value). // 每次approve方法被成功调用后,都必须触发 Approval事件; event Approval(address indexed _owner, address indexed _spender, uint256 _value)};}
"ERC20代币标准怎么实现"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
数量
地址
事件
成功
标准
代币
内容
实际
方法
更多
知识
逻辑
e.g.
实用
相同
学有所成
接下来
余额
再次
合约
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
选货软件开发
河北办公系统软件开发正规平台
万拓互联网科技诈骗
fm2021 1112数据库
2077大曝光数据库
网安支队网络安全等级保护
安徽安庆dns服务器云主机
三级数据库技术2013
os软件开发
php删除文件和数据库
甘肃新一代网络技术服务
网络技术真题2018
数据库union
ec20软件开发
个人软件开发平台最新正式版
电脑时间与网络同步服务器ip
服务器一键装机进不了系统
数据库tns组成
中国医学数据库收费方式
网络安全是第几套主席令
黄庆生网络安全
360做网络安全这块怎么样
php删除文件和数据库
外国人唱歌软件开发
国内数据库运维平台有哪些
相城区提供网络技术哪家好
用服务器搭知识库
滨州crm管理软件开发公司
数据库表权限设计
网络安全手抄报a3纸简单漂亮