简体   繁体   English

单个合约中多个代币的 ERC20

[英]ERC20 for Multiple Tokens in a single contract

I am trying to make a contract that has two different tokens used for different aspects of the contract.我正在尝试制定一份合同,其中包含用于合同不同方面的两种不同代币。 I would like both of the tokens to be able to fit ERC20 standards but I am not sure how to specify unique variables and functions for each.我希望这两个令牌都能够符合 ERC20 标准,但我不确定如何为每个令牌指定唯一的变量和函数。

If you consider the structure of an ERC 20 token : https://github.com/ConsenSys/Tokens/blob/master/Token_Contracts/contracts/Token.sol , you will see that what you are proposing, although possible, would be a little messy.如果您考虑 ERC 20 代币的结构: https : //github.com/ConsenSys/Tokens/blob/master/Token_Contracts/contracts/Token.sol ,您将看到您所提议的,尽管可能,将是一个有点乱。 But more importantly it would transform your token contract into a non-ERC20 token .但更重要的是,它会将您的代币合约转换为非 ERC20 代币

uint256 public totalSupply; uint256 公共总供应量; would need to be replaced with either a mapping or a two separate parameters.需要用映射或两个单独的参数替换。

The same would be for managing balances, you would need to change the signature of each method to take an additional parameter for specifying the token you want or create specific method for each token within the contract:管理余额也是如此,您需要更改每个方法的签名以采用附加参数来指定您想要的代币或为合约中的每个代币创建特定方法:

function balanceOf(address _owner) constant returns (uint256 balance); 函数 balanceOf(address _owner) 常量返回 (uint256 balance);

Would need to be either:需要是:

function balanceOf(address _owner, uint256 token_id) constant returns (uint256 balance);

or或者

function balanceOfTokenA(address _owner) constant returns (uint256 balance);

function balanceOfTokenB(address _owner) constant returns (uint256 balance);

But like I said, either implementation would make your token contract a non-ERC20 token.但就像我说的,任何一种实现都会使您的代币合约成为非 ERC20 代币。


You would be better off having two contracts, then both would be ERC20 compatible.你最好有两个合约,然后两者都兼容 ERC20。 You could then write a third contract for managing them if your requirements are that they need to be interfaced via a single contract.如果您的要求是它们需要通过单个合同进行接口,那么您可以编写第三个合同来管理它们。

These days, ERC1155, a "multi-token" standard, seems like a good choice for contracts needing multiple tokens:如今,“多代币”标准 ERC1155 似乎是需要多个代币的合约的不错选择:

https://github.com/ethereum/EIPs/issues/1155 https://github.com/ethereum/EIPs/issues/1155

Simple Summary:简单总结:

A standard interface for contracts that manage multiple token types.管理多种代币类型的合约的标准接口。 A single deployed contract may include any combination of fungible tokens, non-fungible tokens or other configurations (eg semi-fungible tokens).单个部署的合约可以包括可替代代币、不可替代代币或其他配置(例如半可替代代币)的任意组合。

See also the openzeppelin implementation另请参阅openzeppelin 实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM