【问题标题】:Solidity: solidity declarationerror identifier not found or not uniqueSolidity:solidity 声明错误标识符未找到或不唯一
【发布时间】:2021-07-31 13:01:29
【问题描述】:

尝试使用 REMIX IDE 创建我的第一个智能合约,但遇到了声明错误。 这是我的合约代码

/**** 代码开始 **/

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.2;

import "./Context.sol";
import "./IBEP20.sol";
import "./SafeMath.sol";
import "./Ownable.sol";

contract SampleTaken is Context, IBEP20, Ownable {
    
    
    mapping(address => unit) public balances;
    
    unit public totalSupply = 1000000 * 10 ** 18;
    String public name ="Sample Token";
    String public symbol ="KJA";
    unit public decimals = 18;
    
    /** Events aailable for the Contract**/
    
    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    
    constructor(){
        balances[msg.sender] = totalSupply;
    }
    
    function balanceOf(address _ownerAddress) public view returns (unit){
        return balances[_ownerAddress];
    }
    
  

    
    function transfer(address _toAddress, unit _noOfTokens) public view returns (bool){
    require(balanceOf(msg.sender) >= _noOfTokens, "Total balance is less than the number of Tokens asked for !!!");
    balances[_toAddress] +=_noOfTokens;
    balances[msg.sender] -= _noOfTokens;
    emit Transfer(msg.sender,_toAddress, _noOfTokens);
    return true;
    }
    
    function transferFrom(address _from, address _to, uint _value) public returns (bool){
     require(balanceOf(_from) >= _value, "Balance is less than the number of Tokens asked for !!!");
     require(allowance[_from][msg.sender] >= _value, "Allowance too low");
     balances[_to] += _value;
     balances[_from] -= _value;   
     
     emit Transfer (_from, _to, _value);
     return true;
     
     
    }
    
}

在尝试编译时,我收到以下错误

DeclarationError: Identifier not found or not unique. --> SampleToken.sol:13:24: | 13 | mapping(address => unit) public balances; | ^^^^

这里可能缺少什么?

谢谢 山姆

【问题讨论】:

    标签: blockchain ethereum solidity bep20


    【解决方案1】:

    错误是由您的代码中的拼写错误引起的。

    它应该是uint(无符号整数)——而不是unit

    【讨论】:

    • 非常感谢 Petr..我修正了所有这些错别字..但是遇到了一些其他问题。
    • TypeError:函数声明为视图,但此表达式(可能)修改了状态,因此需要不可支付(默认)或应付。 *** 这是代码行,balances[_toAddress] +=_noOfTokens;余额[msg.sender] -= _noOfTokens;
    • 尝试修复其他问题。有时错误消息会告诉您需要做什么,例如“它被声明为view,但它不仅仅是view”:-) 如果您遇到了死胡同,您可以提出一个单独的问题来显示您的操作到目前为止已经尝试过,最小的可重现代码示例、错误消息等。您可以在FAQhelp center 文章中找到更多如何提出好问题的提示。
    • 当然,彼得。让我用代码 sn-ps 发布一个单独的问题。非常感谢!
    猜你喜欢
    • 2022-10-23
    • 1970-01-01
    • 2019-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2013-01-22
    • 2011-10-25
    相关资源
    最近更新 更多