[英]Solidity ParserError: Expected ';' but got 'is'
I've been learning solidity, however, I am still very new.我一直在学习solidity,但是,我还是很新。 Currently I am making a ERC20 Token but I am having some difficulties with doing so.
目前我正在制作 ERC20 代币,但这样做有一些困难。 Here is what I have.
这就是我所拥有的。
// 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));
}
The Error I recieve when trying to compile the contract is as follows:我在尝试编译合同时收到的错误如下:
ParserError: Expected ';' ParserError:预期的';' but got 'is' --> GToken.sol:7:21: |
但得到了'是'--> GToken.sol:7:21: | 7 |
7 | Contract GToken is ERC20 { |
合约 GToken 为 ERC20 { | ^^
^^
You have two syntax errors in your code:您的代码中有两个语法错误:
contract
should be lowercase, not Contract
contract
应该是小写的,而不是Contract
constructor
is missing closing brace }
constructor
缺少右括号}
Then you're going to run into a type conversion error with the uint(decimals)
.然后你会遇到
uint(decimals)
的类型转换错误。 When you look at the remote contract, you see that decimals() is a view function - not a property.当您查看远程合同时,您会看到 decimals ()是一个视图 function - 不是属性。 So you should read its value as if you were calling a function:
decimals()
.因此,您应该像调用 function: decimals
decimals()
一样读取它的值。
Combined all together:结合在一起:
// 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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.