**Hey guys ! I just try to make a contract for create a contract.
It supposed to be ERC-20 interface so my first contract for this.
But I don’t know how can I do _mint and createContract functions
I got errors so anyone can help me ? I will be appreciative** pragma solidity ^0.5.0;
library SafeMath {
function add(uint a, uint b) internal pure returns (uint c) {
c = a + b;
require(c >= a);
}
function sub(uint a, uint b) internal pure returns (uint c) {
require(b <= a);
c = a - b;
}
function mul(uint a, uint b) internal pure returns (uint c) {
c = a * b;
require(a == 0 || c / a == b);
}
function div(uint a, uint b) internal pure returns (uint c) {
require(b > 0);
c = a / b;
}
}
contract SubToken {
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);
function mint(address from, uint amount) public returns(bool success);
constructor(string memory name,string memory symbol,uint8 decimals,uint256 initialSupply)
public{
mint(msg.sender, initialSupply);
}
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 => SubToken) public tokenlist;
address[] public contracts;
address owner = msg.sender;
using SafeMath for uint;
string public symbol;
string public name;
uint8 public decimals;
uint _totalSupply;
constructor(string memory name,string memory symbol,uint8 decimals,uint256 initialSupply) public{
_mint(msg.sender, initialSupply);
}
function _mint(address account, uint256 amount) internal {
//require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
//emit Transfer(address(0), account, amount);
}
function createNewContract(string memory name,string memory symbol,uint8 decimals,uint256 initialSupply) public returns(address newContract){
SubToken st = new SubToken(name,symbol,decimals,initialSupply);
contracts.push(st);
return st;
}
}
errors is here :
browser/crtcont2.sol:49:19: TypeError: Trying to create an instance of an abstract contract. SubToken st = new SubToken(); ^----------^ browser/crtcont2.sol:14:5: Missing implementation: function allowance(address tokenOwner, address spender) public view returns (uint remaining); ^-------------------------------------------------------------------------------------------^ browser/crtcont2.sol:16:5: Missing implementation: function approve(address spender, uint tokens) public returns (bool success); ^---------------------------------------------------------------------------^ browser/crtcont2.sol:13:5: Missing implementation: function balanceOf(address tokenOwner) public view returns (uint balance); ^------------------------------------------------------------------------^ browser/crtcont2.sol:18:5: Missing implementation: function mint(address from, uint amount) public returns(bool success); ^--------------------------------------------------------------------^ browser/crtcont2.sol:12:5: Missing implementation: function totalSupply() public view returns (uint); ^------------------------------------------------^ browser/crtcont2.sol:15:5: Missing implementation: function transfer(address to, uint tokens) public returns (bool success); ^-----------------------------------------------------------------------^ browser/crtcont2.sol:17:5: Missing implementation: function transferFrom(address from, address to, uint tokens) public returns (bool success); ^-----------------------------------------------------------------------------------------^
browser/crtcont2.sol:50:20: TypeError: Invalid type for argument in function call. Invalid implicit conversion from contract SubToken to address requested. contracts.push(st); ^^
browser/crtcont2.sol:51:12: TypeError: Return argument type contract SubToken is not implicitly convertible to expected type (type of first return variable) address. return st; ^^
it will suppose to be my constructor but I dont know how can I fix :(