0

So i am doing a factory for an ERC20 token contract, here is my factory code:

pragma solidity >= 0.4.0 < 0.6.0;

import "./ERC20.sol";
import "./ERC20Interface.sol";

contract Factory {
    address[] createdContract;
    mapping (address => uint256) contractNo;
    mapping (address => address) contractOwner;
    mapping (address => bool) isEIP20;
    address owner;

    event NewContractCreated(address newContractAddress, address contractCreator);

    constructor() public {
        owner = msg.sender;
    }

    function createNewContract() payable public returns(address) {
        ERC20 newContract = new ERC20();

        newContract.EIP20();
        createdContract.push(address(newContract));
        isEIP20[address(newContract)] = true;
        contractNo[msg.sender]++;
        contractOwner[address(newContract)] = msg.sender;

        emit NewContractCreated(address(newContract), msg.sender);
    }

    function transfer(address _to, address _contractAddress)  public returns (bool) {
        ERC20Interface contractUsed = ERC20Interface(_contractAddress);
        require(contractUsed.transfer(_to, 50));
        return true;
    }

    function ownedContract() public view returns(uint256) {
        return contractNo[msg.sender];
    }

    function ownerOfContract(address _contractAddress) public view returns(address) {
        return contractOwner[_contractAddress];
    }
}

then i deploy it on ganache test rpc using truffle, then i create a new ERC20 from the factory contract and then check for NewContractCreated event and it fine, it return the result i was expecting: Event 1

then i call transfer function from factory contract, then see the NewContractCreated event again but i got empty as a result: Event 2

So where did all my past event from before go, and how did it disapear?

0

Don't know if somebody will get into this kind of problem but the solution to my problem is when using web3js i just have to type MyContract.getPastEvent("MyEvent", {fromBlock: 0}) and it will print out for all event. Don't know how this work but it just work

  • When you use fromBlock:0, it will show all the events from the first block. – Uahmed Feb 28 at 14:48

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.