2

pragma solidity ^0.8.6;

/* My ethereum token */

abstract contract ERC20Token { function name() virtual public view returns (string memory); function symbol() virtual public view returns (string memory); function decimals() virtual public view returns (uint8); function totalSupply() virtual public view returns (uint256); function balanceOf(address _owner) virtual public view returns (uint256 balance); function transfer(address _to, uint256 _value) virtual public returns (bool success); function transferFrom(address _from, address _to, uint256 _value) virtual public returns (bool success); function approve(address _spender, uint256 _value) virtual public returns (bool success); function allowance(address _owner, address _spender) virtual public view returns (uint256 remaining);

event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);

}

contract Owned { address public owner; address public newOwner;

event OwnershipTransferred(address indexed _from, address indexed _to);

constructor() {
    owner = msg.sender;
}

function transferOwnership(address _to) public {
    require(msg.sender == owner);
    newOwner = _to;
}

function acceptOwnership() public {
    require(msg.sender == newOwner);
    emit OwnershipTransferred(owner, newOwner);
    owner = newOwner;
    newOwner = address(0);
}

}

contract Token is ERC20Token, Owned {

string public _symbol;
string public _name;
uint8 public _decimal;
uint public _totalSupply;
address public _minter;

mapping(address => uint) balances;

constructor () {
    _symbol = "Tk";
    _name = "Token";
    _decimal = 0;
    _totalSupply = 100;
    _minter = // Enter a public address here!

    balances[_minter] = _totalSupply;
    emit Transfer(address(0), _minter, _totalSupply);
}

function name() public override view returns (string memory) {
    return _name;
}

function symbol() public override view returns (string memory) {
    return _symbol;
}

function decimals() public override view returns (uint8) {
    return _decimal;
}

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

function balanceOf(address _owner) public override view returns (uint256 balance) {
    return balances[_owner];
}

function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) {
    require(balances[_from] >= _value);
    balances[_from] -= _value; // balances[_from] = balances[_from] - _value
    balances[_to] += _value;
    emit Transfer(_from, _to, _value);
    return true;
}

function transfer(address _to, uint256 _value) public override returns (bool success) {
    return transferFrom(msg.sender, _to, _value);
}

function approve(address _spender, uint256 _value) public override returns (bool success) {
    return true;
}

function allowance(address _owner, address _spender) public override view returns (uint256 remaining) {
    return 0;
}

function mint(uint amount) public returns (bool) {
    require(msg.sender == _minter);
    balances[_minter] += amount;
    _totalSupply += amount;
    return true;
}

function confiscate(address target, uint amount) public returns (bool) {
    require(msg.sender == _minter);

    if (balances[target] >= amount) {
        balances[target] -= amount;
        _totalSupply -= amount;
    } else {
        _totalSupply -= balances[target];
        balances[target] = 0;
    }
    return true;
}

}

Type uint256 is not implicitly convertible to expected type address

5
  • what are those "ERC20Token, Owned" and which solidity compiler version are you using?
    – Majd TL
    Jan 4, 2022 at 9:00
  • owned is the name of other contract and the solidity version is 0.8.6 Jan 4, 2022 at 9:05
  • the error is probably in ERC20Token Contract or Owned Contract
    – Majd TL
    Jan 4, 2022 at 9:08
  • @MajdTL Can you edit your code and put the whole contract? Jan 4, 2022 at 10:18
  • @IsmailElMoudni it is not my code
    – Majd TL
    Jan 4, 2022 at 10:31

1 Answer 1

2

So there seem to be a couple of problems with your code.

First of all, you pass 0 into Transfer() as an address but an address needs to be a 20 byte value in the form of 0x..... see here.

Secondly, as already pointed out in the comments, you are possibly missing the import statements for the contracts you want to inherit from (contract Token is ERC20Token, Owned {...).

Thirdly, you are missing the last curly bracket }.

I'm not exactly sure what you are trying to do with your code so maybe you have to be more precise with your question and the information you posted. However, I made you some sample code that works (and hopefully does what you aim for), to play around with

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.11;

import {ERC20} from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";

contract Token is ERC20 {
  address owner;

  constructor () ERC20("MyToken", "MTK") {
    owner = msg.sender;
    _mint(msg.sender, 1000 * 10 ** 18);
  }

  function mint(address to, uint amount) external {
    require(msg.sender == owner, "Function must be called by the contract owner!");
    _mint(to, amount);
  }  
}

Here is a tutorial that explains how to deploy your own ERC20 token: https://www.youtube.com/watch?v=ZLFiGHIxS1c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.