我一直在学习稳固,然而,我仍然是非常新的。目前,我正在制作一个ERC20令牌,但是我在这样做时遇到了一些困难。这是我所拥有的。
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol";
Contract GToken is ERC20 {
constructor(string memory name, string memory symbol)
ERC20("GToken", "GTKN") public {
_mint(msg.sender, 1000000 * 10 ** uint(decimals));
}在试图编译合同时,我所收到的错误如下:
ParserError:期望值';‘但得到’是‘-> GToken.sol:7:21:\7\\合同GToken是ERC20 {x^
发布于 2021-06-01 23:22:59
代码中有两个语法错误:
contract应该是小写的,而不是Contractconstructor缺少关闭大括号}然后,您将在uint(decimals)中遇到类型转换错误。当您查看远程契约时,您会看到小数()是一个视图函数,而不是一个属性。因此,您应该像调用函数:decimals()一样读取它的值。
合并在一起:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
// removed the IERC20 import, not needed in this context
contract GToken is ERC20 {
constructor(string memory name, string memory symbol) ERC20("GToken", "GTKN") public {
_mint(msg.sender, 1000000 * 10 ** decimals()); // calling the `decimals()` function
}
}https://stackoverflow.com/questions/67796286
复制相似问题