简体   繁体   English

Solidity ParserError:预期的';' 但得到了“是”

[英]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.

相关问题 坚固性:ParserError:预期';' 但得到'(' - solidity: ParserError: Expected ';' but got '(' Solidity ParserError:预期的标识符,但得到了 '(' constructor() public { ^ - Solidity ParserError: Expected identifier but got '(' constuctor() public { ^ Solidity 错误:: ParserError: Expected '(' but got 'public' - Solidity Error :: ParserError: Expected '(' but got 'public' "Solidity 错误 :: ParserError: Expected ',' but got 'Number'" - Solidity Error :: ParserError: Expected ',' but got 'Number' SOLIDITY:[函数覆盖]:-> ParserError:预期为“{”但得到保留关键字“覆盖” - SOLIDITY : [Function Overridding] : -> ParserError: Expected '{' but got reserved keyword 'override' Solidity 中的 ParserError,预期的标识符但得到保留关键字“不可变” - ParserError in solidity, Expected identifier but got reserved keyword 'immutable' 无法解决 Solidity 错误 - ParserError: Expected ';' 但得到了“数字”-> first.sol:2:17: | 2 | Pragma 坚固性 0.8.7; | ^^^ - Unable to solve solidity error- ParserError: Expected ';' but got 'Number' --> first.sol:2:17: | 2 | Pragma solidity 0.8.7; | ^^^ 解析器错误:应为“;” 但得到了标识符 - ParserError: Expected ';' but got identifier ParserError:应为“;” 但得到了“事件”——solidity 0.8 address payable(msg.sender) - ParserError: Expected ';' but got 'event' -- solidity 0.8 address payable(msg.sender) ParserError:应为“;” 但得到了保留关键字“in” - ParserError: Expected ';' but got reserved keyword 'in'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM