Hi Guys 👋
I have two contacts first one is SubToken and second one is MainContract.
First I deploy MainContract after that I use createNewContract function and I create new SubToken.
and then
I deploy SubToken with a address which is come from create contract function in my MainContract.
I want to access my name and I make a few functions in SubToken contract for that but I see revert error :(
VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
I dont know what am I supposed to do. Anyone can help me please :)
Here's the a few ss of my code:
https://eksiup.com/p/aj79538kzmgp
https://eksiup.com/p/w779539wzqmc
https://eksiup.com/p/9t79541aevh6
pragma solidity ^0.5.0;
import 'https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol';
contract SubToken{
MainContract mc;
constructor(address _address) public{
mc=MainContract(_address);
}
function getName1() view public returns(string memory){
return mc.getNameMain(address(this));
}
//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 => mapping(address=>uint)) balances;
//mapping(address => mapping(address => uint)) allowed;
address[] public contracts;
using SafeMath for uint;
address contract_address;
struct token{
string name;
string symbol;
uint8 decimals;
uint totalSupply;
uint balances;
}
mapping(address => token) public tokens;
address mycontraddress;
function createNewContract(string memory _name,string memory _symbol,uint8 _decimals,uint256 _totalSupply,uint _balance) public returns(address youraddress){
SubToken st = new SubToken(address(this));//address(this)
tokens[address(st)] = token(_name,_symbol,_decimals,_totalSupply,_balance);
mycontraddress=address(st);
return mycontraddress;
}
function seeContracttAddress() public view returns(address){
return mycontraddress;
}
function getNameMain(address _address) public view returns(string memory){
return tokens[_address].name;
}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}