问题设置了ERC20合同中最大量的令牌

发布于 2025-02-11 06:57:29 字数 555 浏览 0 评论 0原文

我一直在尝试在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2025-02-18 06:57:29

EVM不支持十进制数字(以防止与在不同架构上运行的网络节点相关的四舍五入错误),因此所有数字都是整数。

erc-20 token标准标准定义decimals()>您的合同,有效地通过声明的零数将所有数字移动以模拟小数。

因此,如果您想用18个小数铸造1个令牌,则需要通过值100000000000000000000(18 ZEROS)。或与您的情况一样,有100万个令牌(6个零)为> 1000000000000000000000000000000(24 Zeros)。相反的情况也是如此,有18个小数的令牌为0.5是5000000000000000(17 ZEROS)。

您还可以使用下划线(它们在视觉上除了视觉上分开值外什么都没有做任何事情)和科学符号来减轻人类错误,同时使用如此大量的零零:

// 6 zeros and 18 zeros => 24 zeros
_totalSupply = 1_000_000 * 1e18;

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 as 1000000000000000000000000 (24 zeros). Same goes the other way around, 0.5 of a token with 18 decimals is 500000000000000000 (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:

// 6 zeros and 18 zeros => 24 zeros
_totalSupply = 1_000_000 * 1e18;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文