简体   繁体   English

为什么我的代码在 remix 上显示 pragma 错误?

[英]Why my code showing pragma error on remix?

I'm practicing with some open codes.我正在练习一些开放代码。 also I'm pretty new on solidity.我对坚固性也很陌生。 When i try to compile my code, it keep getting this Error: browser/grow.sol:1:1: Warning: Source file does not specify required compiler version!当我尝试编译我的代码时,它不断收到此错误: browser/grow.sol:1:1: 警告:源文件未指定所需的编译器版本! Consider adding "pragma solidity ^0.5.0;"考虑添加“pragma solidity ^0.5.0;” ^ . ^ I'm using REMIX & compiler version 0.5.0我正在使用 REMIX 和编译器版本 0.5.0

    /**
 *Submitted for verification at Etherscan.io on 2020-08-25
*/

pragma solidity ^0.5.0;

contract ERC20Interface {
    function totalSupply() 
        public 
        view 
        returns (uint);

    function balanceOf(address tokenOwner) 
        public 
        view 
        returns (uint balance);
    
    function allowance
        (address tokenOwner, address spender) 
        public 
        view 
        returns (uint remaining);

    function transfer(address to, uint tokens)              public 
        returns (bool success);
    
    function approve(address spender, uint tokens)      public 
        returns (bool success);

    function transferFrom 
        (address from, address to, uint tokens)                 public 
        returns (bool success);


    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
    
    
}

contract SafeMath {
    function safeAdd(uint a, uint b) public pure returns (uint c) {
        c = a + b;
        require(c >= a);
    }
    function safeSub(uint a, uint b) public pure returns (uint c) {
        require(b <= a); c = a - b; } function safeMul(uint a, uint b) public pure returns (uint c) { c = a * b; require(a == 0 || c / a == b); } function safeDiv(uint a, uint b) public pure returns (uint c) { require(b > 0);
        c = a / b;
    }
}


contract MYTOKEN is ERC20Interface, SafeMath {
    string public name;
    string public symbol;
    uint8 public decimals; 
    
    uint256 public _totalSupply;
    
    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;

    constructor() public {
        name = "MYTOKEN";
        symbol = "MYT";
        decimals = 18;
        
        _totalSupply = 1000000000000000000000000;
        
        balances[msg.sender] = _totalSupply;
        emit Transfer(address(0), msg.sender, _totalSupply);
    }
    
    
    function totalSupply() public view returns (uint) {
        return _totalSupply - balances[address(0)];
    }
    
    function balanceOf(address tokenOwner) public view returns (uint balance) {
        return balances[tokenOwner];
    }

    function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
        return allowed[tokenOwner][spender];
    }

    function approve(address spender, uint tokens) public returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        return true;
        
    }
    
    function transfer(address to, uint tokens) public returns (bool success) {
        balances[msg.sender] = safeSub(balances[msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(msg.sender, to, tokens);
        return true;
    }
    
    function transferFrom(address from, address to, uint tokens) public returns (bool success) {
        balances[from] = safeSub(balances[from], tokens);
        allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(from, to, tokens);
        return true;
    }
    
}

No errors on my side.我这边没有错误。 Have you tried to recompile your code once you've haded the pragma statement?一旦你有了pragma语句,你是否尝试过重新编译你的代码? In remix, you can recompile your code in the SOLIDITY COMPILER section (left side of the screen).在 remix 中,您可以在SOLIDITY COMPILER部分(屏幕左侧)重新编译您的代码。 Sometimes error stays until code is recompiled.有时错误会一直持续到重新编译代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Solidity 智能合约代码中的预期未知错误 - Remix - Solidity Expected unidentified error in smart contract code - Remix 为什么我的for循环应该显示标识符错误? - why is my for loop expected showing identifier error? 为什么在我运行 c 代码时显示错误“collect2.exe:错误:ld 返回 1 退出状态” - Why is the error “collect2.exe: error: ld returned 1 exit status” showing when I run my c code SOLIDITY REMIX 编译器,在部署我的合约后收到此错误(无效的 BigNumber 字符串) - SOLIDITY REMIX compiler, after deploying my contract getting this ERROR (Invalid BigNumber string) 创建方法时,我的Java代码显示了编译器错误 - My Java code is showing a compiler error when I create method 为什么我的代码中出现 CS1001 错误? - Why am I getting a CS1001 error in my code? 为什么我的程序在使用 foreach 循环迭代 ArrayList 时显示这种类型的错误? - Why my Program is showing this type of Error while iterating ArrayList using foreach loop? 为什么在我的代码生成程序中出现此语法错误? - Why do I get this syntax error in my code generating program? 当我在 if 条件语句中使用 '=' 而不是 '==' 时,为什么我的编译器没有显示错误? - Why is my compiler not showing an error when I'm using '=' instead of '==' in if conditional statement? 不稳定的混音编译器错误“编译期间未知异常” - Unstable remix compiler error “Unknown exception during compilation”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM