ERC20 代币:地址(0)是什么?初始代币分配的最佳实践?
ERC20 Token: What is address(0)? And best practices for initial token distribution?
我有一个漂亮的样板测试令牌,我将使用它来支持 DApp 项目。我有疑问的主要功能如下:
constructor() {
name = "Test Token";
symbol = "TTKN";
decimals = 18;
_totalSupply = 1000000000000000000000000000000;
//WITHOUT DECIMALS = 1,000,000,000,000; should be 1 trillion
balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
function totalSupply() public override view returns (uint256) {
return _totalSupply - balances[address(0)];
}
首先,一个关于小数和供应的快速问题:我是否正确设置了它来创建 1 万亿的 TTKN 代币?我真的需要那么多小数位吗?
其次,address(0)
到底是什么?我对构造函数的理解是address(0)
先把全部的代币转给msg.sender
,也就是我这个合约的部署者
最后,最初分发代币的最佳做法是什么?我想要的基本如下:
a) 我自己和其他一些开发者每人获得初始供应量的 1%
b) 我们的 DApp,一个单独的智能合约,将获得初始供应量的 50%,并将用它来奖励与我们的 website/project
互动的用户
c) 为了完成 a) 和 b),我作为合约部署者是否应该按计划手动转移这些代币?
d) 其余的硬币......可以以某种方式进行交换(可能超出问题范围)
现在我已经在 remix 上部署了这个测试代币,并且对如何围绕代币进行转移有了一些了解,我想了解与我们的项目相关的上述几点。我的计划是否普遍可接受且可行,作为最初的所有者,我最终在部署时是否只是在 ETH 主网上进行了一堆 transfer
调用?
did I set this up correctly to create 1 trillion of the TTKN token?
这是正确的方法之一。也更具可读性:
_totalSupply = 1000000000000 * 1e18;
或
// 10 to the power of
_totalSupply = 1000000000000 * (10 ** decimals);
^^ 请注意,此代码段执行存储读取(decimals
变量),因此它的 gas-wise
更昂贵
还有
_totalSupply = 1000000000000 ether;
^^ 使用 ether 单位,* 1e18
的别名
what exactly is address(0)
如果它在 Transfer 事件的第一个参数中,则意味着令牌已被铸造。如果在第二个参数中,则表示销毁代币。
A token contract which creates new tokens SHOULD trigger a Transfer event with the _from
address set to 0x0
when tokens are created.
来源:https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer-1
initially distributing the tokens
您可以在构造函数中执行分配。为了简单起见,我的示例将“交易所”显示为由您的团队管理的常规地址,该地址将手动将代币发送到交易所。但也可以自动在 DEX 上列出代币。
_totalSupply = 1000000000000 * 1e18;
address[3] memory devs = [address(0x123), address(0x456), address(0x789)];
address dapp = address(0xabc);
address exchange = address(0xdef);
// helper variable to calculate the remaining balance for the exchange
uint256 totalSupplyRemaining = _totalSupply;
// 1% for each of the devs
uint256 devBalance = _totalSupply / 100;
for (uint i = 0; i < 3; i++) {
balances[devs[i]] = devBalance;
emit Transfer(address(0x0), devs[i], devBalance);
totalSupplyRemaining -= devBalance;
}
// 50% for the DApp
uint256 dappBalance = _totalSupply / 2;
balances[dapp] = dappBalance;
emit Transfer(address(0x0), dapp, dappBalance);
totalSupplyRemaining -= dappBalance;
// the rest for the exchange
balances[exchange] = totalSupplyRemaining;
emit Transfer(address(0x0), exchange, totalSupplyRemaining);
我有一个漂亮的样板测试令牌,我将使用它来支持 DApp 项目。我有疑问的主要功能如下:
constructor() {
name = "Test Token";
symbol = "TTKN";
decimals = 18;
_totalSupply = 1000000000000000000000000000000;
//WITHOUT DECIMALS = 1,000,000,000,000; should be 1 trillion
balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}
function totalSupply() public override view returns (uint256) {
return _totalSupply - balances[address(0)];
}
首先,一个关于小数和供应的快速问题:我是否正确设置了它来创建 1 万亿的 TTKN 代币?我真的需要那么多小数位吗?
其次,address(0)
到底是什么?我对构造函数的理解是address(0)
先把全部的代币转给msg.sender
,也就是我这个合约的部署者
最后,最初分发代币的最佳做法是什么?我想要的基本如下:
a) 我自己和其他一些开发者每人获得初始供应量的 1%
b) 我们的 DApp,一个单独的智能合约,将获得初始供应量的 50%,并将用它来奖励与我们的 website/project
互动的用户c) 为了完成 a) 和 b),我作为合约部署者是否应该按计划手动转移这些代币?
d) 其余的硬币......可以以某种方式进行交换(可能超出问题范围)
现在我已经在 remix 上部署了这个测试代币,并且对如何围绕代币进行转移有了一些了解,我想了解与我们的项目相关的上述几点。我的计划是否普遍可接受且可行,作为最初的所有者,我最终在部署时是否只是在 ETH 主网上进行了一堆 transfer
调用?
did I set this up correctly to create 1 trillion of the TTKN token?
这是正确的方法之一。也更具可读性:
_totalSupply = 1000000000000 * 1e18;
或
// 10 to the power of
_totalSupply = 1000000000000 * (10 ** decimals);
^^ 请注意,此代码段执行存储读取(decimals
变量),因此它的 gas-wise
还有
_totalSupply = 1000000000000 ether;
^^ 使用 ether 单位,* 1e18
what exactly is address(0)
如果它在 Transfer 事件的第一个参数中,则意味着令牌已被铸造。如果在第二个参数中,则表示销毁代币。
A token contract which creates new tokens SHOULD trigger a Transfer event with the
_from
address set to0x0
when tokens are created.
来源:https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md#transfer-1
initially distributing the tokens
您可以在构造函数中执行分配。为了简单起见,我的示例将“交易所”显示为由您的团队管理的常规地址,该地址将手动将代币发送到交易所。但也可以自动在 DEX 上列出代币。
_totalSupply = 1000000000000 * 1e18;
address[3] memory devs = [address(0x123), address(0x456), address(0x789)];
address dapp = address(0xabc);
address exchange = address(0xdef);
// helper variable to calculate the remaining balance for the exchange
uint256 totalSupplyRemaining = _totalSupply;
// 1% for each of the devs
uint256 devBalance = _totalSupply / 100;
for (uint i = 0; i < 3; i++) {
balances[devs[i]] = devBalance;
emit Transfer(address(0x0), devs[i], devBalance);
totalSupplyRemaining -= devBalance;
}
// 50% for the DApp
uint256 dappBalance = _totalSupply / 2;
balances[dapp] = dappBalance;
emit Transfer(address(0x0), dapp, dappBalance);
totalSupplyRemaining -= dappBalance;
// the rest for the exchange
balances[exchange] = totalSupplyRemaining;
emit Transfer(address(0x0), exchange, totalSupplyRemaining);