0

Trying to create my first smart contract with the REMIX IDE, however getting into a Declaration Error. Here is the code of my contract

/**** Code start **/

// 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;
     
     
    }
    
}

While trying to compile it, I am getting the following error

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

What could be missing here?

Thanks Sam

BlockChain Learner
  • 125
  • 1
  • 10
  • 18

2 Answers2

3

The error is caused by a typo in your code.

It's supposed to be uint (unsigned integer) - not unit.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
  • Thank you so much Petr..I fixed all those typos..However ran into some other issues. – BlockChain Learner May 10 '21 at 08:07
  • TypeError: Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable. *** This is the line of code, balances[_toAddress] +=_noOfTokens; balances[msg.sender] -= _noOfTokens; – BlockChain Learner May 10 '21 at 08:10
  • 1
    Try fixing the other issues as well. Sometimes the error message tells you what you need to do, such as "it's declared as `view` but it's not doing just `view`" :-) If you run into a dead end, you can ask a separate question showing what you've tried so far, the minimal reproducible code example, error message, etc. You can find more tips how to ask a good question in the [FAQ] and [help] articles. – Petr Hejda May 10 '21 at 08:12
  • Sure Peter. Let me post a separate question with the code snippets. Thanks so much ! – BlockChain Learner May 10 '21 at 08:15
0

This type of error happens when you use an invalid data type (one that is not recognized by solidity).

For examples:

boolean result = true; (boolean is not a valid data type but bool)

const result = 1 + 1; (const is not a valid data type but uint256)

user3670684
  • 1,135
  • 9
  • 8