-3
pragma solidity ^0.5.0;
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol';

contract SubToken{
    mapping(address => uint) balances;

    string  symbol;
    string  name;
    uint8  decimals;
    uint  totalSupply; 

    using SafeMath for uint;

    //subtoken_struct public sub_tokens;

    //mapping(address  => subtoken_struct) public mySubTokens ;

    address contract_address; 

    constructor(string memory _name,string memory _symbol,uint8 _decimals,uint256 _totalSupply)  public{ 
        name = _name; 
        symbol = _symbol; 
        decimals=_decimals; 
        totalSupply = _totalSupply; 
        balances[msg.sender]=_totalSupply; 
    } 
    //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 MainContrat {
    mapping(address => uint) balances;

    mapping(address => mapping(address => uint)) allowed;
    mapping(address => address[]) public created;

    mapping(address => SubToken) public tokenlist;

    address[] public contracts;
    address owner = msg.sender;

    using SafeMath for uint;

    address contract_address;

    function createNewContract(string memory _name,string memory _symbol,uint8 _decimals,uint256 _totalSupply) public returns(address newAddres){ 
        SubToken mc = new SubToken(_name,_symbol,_decimals,_totalSupply); 
        created[msg.sender].push(address(mc)); 
        contracts.push(address(mc)); 
        return address(mc); 
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        emit Transfer(_from, _to, _value);
        return true;
    }
    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);

}

hey guys I have a main contract and have a creteContract function. This function create a new subtoken so I use subToken like a interface.

when I compile my contract I got a error like this :

TypeError: Trying to create an instance of an abstract contract. SubToken mc = new SubToken(_name,_symbol,_decimals,_totalSupply); ^----------^ browser/crtcont7.sol:32:5: Missing implementation: function transferFrom(address from, address to, uint tokens) public returns (bool success); ^-----------------------------------------------------------------------------------------^

  • 2
    The title alone implies that you have some basic misunderstanding of the term abstract. You cannot instantiate an abstract object. This is true not only for Solidity, but for any other object-oriented language. – goodvibration Aug 5 at 8:02
  • Thanks for the comment but can you write correct contract or just re-design my contact again please :) – Furkan Demirel Aug 5 at 8:23
2

You could look at OpenZeppelin Contracts ERC20 Token documentation to see if this meets your needs for an ERC20 Token. You may also want to use the OpenZeppelin IERC20 interface.

Note that you should only use OpenZeppelin code published in an official release, so you should include the version tag in your import when using Remix or you can take a look at the Getting Started guide for information on how to setup a development environment.

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.3.0/contracts/math/SafeMath.sol";

You can also ask questions about how to use OpenZeppelin Contracts in the Community Forum

Disclosure: I am the the Community Manager at OpenZeppelin

  • 1
    thank you so much I am appreciative – Furkan Demirel Aug 6 at 7:48
1
pragma solidity ^0.5.0; 
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol'; 

contract SubToken{ 
    mapping(address => uint) balances; 

    string  symbol; 
    string  name; 
    uint8  decimals; 
    uint  totalSupply;  

    using SafeMath for uint; 

    address contract_address;  

    constructor(string memory _name,string memory _symbol,uint8 _decimals,uint256 _totalSupply)  public{  
        name = _name;  
        symbol = _symbol;  
        decimals=_decimals;  
        totalSupply = _totalSupply;  
        balances[msg.sender]=_totalSupply;  
    }  

    //function transferFrom(address from, address to, uint tokens) public returns (bool success); 
    //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 MainContract { 
    mapping(address => uint) balances; 

    mapping(address => mapping(address => uint)) allowed; 
    mapping(address => address[]) public created; 

    mapping(address => SubToken) public tokenlist; 

    address[] public contracts; 
    address owner = msg.sender; 

    using SafeMath for uint; 

    address contract_address; 
    /* 

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { 
        emit Transfer(_from, _to, _value); 
        return true; 
    } 
    */ 
    function createNewContract(string memory _name,string memory _symbol,uint8 _decimals,uint256 _totalSupply) public returns(address){  
        SubToken st = new SubToken(_name,_symbol,_decimals,_totalSupply); 
         //st = new SubToken();  
        created[msg.sender].push(address(st));  
        contracts.push(address(st));  
        //return address(mc);  
    }  
    event Transfer(address indexed _from, address indexed _to, uint256 _value); 
    event Approval(address indexed _owner, address indexed _spender, uint256 _value); 

} 

Your Answer

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

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