1

Here's my contract code, now in the ABI I have an anonymous entry and I'm not sure what is that and how can I emit anonymous event.

pragma solidity ^0.4.24;

contract TestContract {
    event Start(uint start, uint middle, uint end);
    event End(uint start, uint middle, uint end);

    uint one;
    uint public two;
    uint public three;

    function setInitialParams(uint _one, uint _two, uint _three) public {
        emit Start(one, two, three);
        one = _one;
        two = _two;
        three = _three;
        emit End(one, two, three);
    }

    function () public {
        revert();
    }
}

Thought maybe it's the anonymous function like fallback but no, here's the ABI of the start event:

{
    "anonymous": false,
    "inputs": [
        {
            "indexed": false,
            "name": "start",
            "type": "uint256"
        },
        {
            "indexed": false,
            "name": "middle",
            "type": "uint256"
        },
        {
            "indexed": false,
            "name": "end",
            "type": "uint256"
        }
    ],
    "name": "Start",
    "type": "event"
}
1

From the Solidity documentation:

If the event is declared as anonymous the topics[0] is not generated

Unlike regular events, anonymous events do not contain an indexed keccak of their signature. Because of this they cannot be easily searched for, or decoded with certainty unless you have the specific contract ABI.

To make an event anonymous, include the anonymous keyword after declaring the variables:

contract TestContract {
    event Start(uint start, uint middle, uint end) anonymous;
    event End(uint start, uint middle, uint end) anonymous;

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.