1

This is my contract

pragma solidity ^'0.5.2';

contract MyContract {
    event ContractCreated(address newAddress);

    constructor() public { }

    function createOtherContract() public {
        address contractAddress = address(contract);
        emit ContractCreated(contractAddress);
    }
}

if I watch the events using this code

MyContract.methods
    .createOtherContract()
    .send({from: accounts[0]})
    .on('transactionHash', function (hash) {

        MyContract.events.allEvents({
                fromBlock: 4477390,
                toBlock: 'latest'
            }, (error, events) => { 
                if (error) { console.log("ERR", error); }
                console.log("Events", JSON.stringify(events)); 
            });

            MyContract.once('ContractCreated', {
                fromBlock: 4477390,
                toBlock: 'latest'
            }, (error, event) => { 
                if (error) { console.log("ERR", error); }
                console.log("My Event", JSON.stringify(event)); 
            });

        })
        .on('confirmation', function (confirmationNumber) {
            console.log("confirmation number", confirmationNumber);
        })
        .on('receipt', function (receipt) {
            console.log("RECEIPT", receipt);
            MyContract.getPastEvents('ContractCreated', {
                fromBlock: 0,
                toBlock: 'latest'
            }, (error, events) => { console.log("Events", events); })
            .then((events) => {
                console.log("Events", events) 
            });

        });

But I do not get any result if try to filter the events by name: That's my console log print:

Your Answer

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

Browse other questions tagged or ask your own question.