1

This is a snippet of my main code:

pragma solidity ^0.6.0;

import 'IERC20.sol';

contract Kaarya is IERC20 {

   uint public constant _totalSupply = 1000000;

   string public constant symbol = "KRY";
   string public constant name = "Kaarya Token";
   uint8 public constant decimals = 3;


   mapping(address => uint256) balances;
   mapping(address => mapping(address => uint256)) allowed;


   constructor() public{
       balances[msg.sender] = _totalSupply;
   }


   function totalSupply() external view returns (uint256) {
       return _totalSupply;
   }


   function balanceOf(address account) external view returns (uint256) {
    return balances[account];
   }


   function transfer(address recipient, uint256 amount) external returns (bool) {
       require (
        balances[msg.sender] >= amount
        && amount > 0
    );
    balances[msg.sender] -= amount;
    balances[recipient] += amount;
    Transfer(msg.sender, recipient, amount);
    return true;
    }

   function transferFrom(address sender, address recipient, uint256 amount) external returns (bool) {
       require(
           allowed[sender][msg.sender] >= amount
           && balances[sender] >= value
           && amount > 0
       );
       balances[sender] -= amount;
       balances[recipient] += amount;
       allowed[sender][msg.sender] -= amount;
       return true;
   }

   function allowance(address owner, address spender) external view returns (uint256) {
       return allowed[owner][spender];
   }

   function approve(address spender, uint256 amount) external returns (bool) {
       allowed[msg.sender][spender] = amount;
       Approval(msg.sender, spender, amount);
       return true;
   }

   event Transfer(address indexed from, address indexed to, uint256 value);

   event Approval(address indexed owner, address indexed spender, uint256 value);

}

I get the error: TypeError: Name has to refer to a struct, enum or contract. Contract Kaarya is IERC20 {

This is a snippet of the code for what I'm importing:

pragma solidity ^0.6.0;

interface IERC20 {

    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

I checked other similar questions in StackExchange but still doesn't work. Any help would be great!

  • 1
    Try without the as IERC20. – goodvibration Mar 7 at 16:20
  • @goodvibration without it I get an error 'Undeclared Identifier' for all variables. – Rohit Handique. Mar 7 at 17:22
  • First of all, before everything, please fix up your question. Those two contracts that you've posted - each one of them misses by the least one closing curly brace. I have the feeling that it's not the only thing missing there, which could explain the error that you're getting. But without seeing your full code, it is impossible to tell. – goodvibration Mar 7 at 17:51
  • as IERC20 is a syntax error. The correct syntax is import {IERC20} from './IERC20.sol'; – Ismael Mar 7 at 19:09
  • @goodvibration Please, be gentle, we are all here because we want to help others. – Ismael Mar 7 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.