Remix

ParserError:需要函式、變數、結構或修飾符聲明。^

  • December 6, 2020
pragma solidity >=0.5.0 <0.6.0;

import 'openzeppelin-solidity/contracts/token/ERC20/ERC20.sol';

contract NautCoin is ERC20 {

 // string public constant name = 'NautCoin';
 // string public constant symbol = '0x0';
 // uint public constant decimals = 18;
 uint public timeLock = now + 1 days;
 uint256 public INITIAL_SUPPLY;
 address public player;

 constructor(address _player) 
 public {
   player = _player;
   INITIAL_SUPPLY = 10000 * (uint256(decimals()));
   // _totalSupply = INITIAL_SUPPLY;
   // _balances[player] = INITIAL_SUPPLY;
   _mint(player, INITIAL_SUPPLY);
   emit Transfer(address(0), player, INITIAL_SUPPLY);
 }
 
 function transfer(address _to, uint256 _value) public returns(bool) {
   super.transfer(_to, _value);
 }
  
 function approve(address _spender, uint256 _value) public returns(bool) {
   super.approve(_spender, _value);  
 }  
   
 // Prevent the initial owner from transferring tokens until the timelock has passed
 modifier lockTokens() {
   if (msg.sender == player) {
     require(now > timeLock);
     _;
   } else {
    _;
   }
 } 
} 

你如何解決這個錯誤?

那是我剛剛做的一些奇怪的故障排除。我在 Remix 中複製粘貼了契約,然後開始摸索到底出了什麼問題。

approve最後,編譯器不喜歡的函式周圍似乎有一些奇怪的空格字元。因此,只需刪除該功能和它周圍的東西,然後用正常空格重寫它,它就可以工作了。

引用自:https://ethereum.stackexchange.com/questions/90841