问题设置了ERC20合同中最大量的令牌
我一直在尝试在Rinkeby网络中创建一个非常简单的ERC20令牌。我将以下代码放入我的.sol文件中,但最大电源似乎不匹配。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Artytoken is ERC20 {
address public admin;
uint private _totalSupply;
constructor() ERC20('ArtyToken', 'AATK') {
admin = msg.sender;
_totalSupply = 1000000;
_mint(admin, _totalSupply);
}
}
在我的metAmask地址中,我拥有“ 0.000000000001”,并且我已经看到在etherscan中,最大总供应了其“ 0.00000000000001”。我在做什么错? 先感谢您! :)
I've been trying to create a very simple ERC20 token with truffle in the rinkeby network. I placed the following code into my .sol file but the max supply doesnt seem to match.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Artytoken is ERC20 {
address public admin;
uint private _totalSupply;
constructor() ERC20('ArtyToken', 'AATK') {
admin = msg.sender;
_totalSupply = 1000000;
_mint(admin, _totalSupply);
}
}
In my Metamask address shows that i own "0.000000000001" and I've seen that in Etherscan it shows that the max total supply its "0.000000000001". What im doing wrong?
Thank you in advance! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EVM不支持十进制数字(以防止与在不同架构上运行的网络节点相关的四舍五入错误),因此所有数字都是整数。
erc-20 token标准标准定义
decimals()
>您的合同,有效地通过声明的零数将所有数字移动以模拟小数。因此,如果您想用18个小数铸造1个令牌,则需要通过值
100000000000000000000
(18 ZEROS)。或与您的情况一样,有100万个令牌(6个零)为> 1000000000000000000000000000000
(24 Zeros)。相反的情况也是如此,有18个小数的令牌为0.5是5000000000000000
(17 ZEROS)。您还可以使用下划线(它们在视觉上除了视觉上分开值外什么都没有做任何事情)和科学符号来减轻人类错误,同时使用如此大量的零零:
The EVM does not support decimal numbers (to prevent rounding errors related to the network nodes running on different architectures), so all numbers are integers.
The ERC-20 token standard defines the
decimals()
function that your contract implements, effectively shifting all numbers by the declared number of zeros to simulate decimals.So if you wanted to mint 1 token with 18 decimals, you'd need to pass the value
1000000000000000000
(18 zeros). Or as in your case, 1 million tokens (6 zeros) with 18 decimals is represented as1000000000000000000000000
(24 zeros). Same goes the other way around, 0.5 of a token with 18 decimals is500000000000000000
(17 zeros).You can also use underscores (they effectively do nothing but visually separate the value) and scientific notation to mitigate human error while working with such large amount of zeros: