Skip to content

Contract events not being emitted reliably  #3486

Open
@firatkaratas

Description

@firatkaratas

Ethers Version

5.6.7

Search Terms

alchemy, event, eventfilter, optimism

Describe the Problem

Hey all,

I'm having a problem with contract events being not reliable as in they are mostly not emitted but sometimes are emitted.

Events from a smart contract (Gnosis Safe contract, SignMsg but true for other events as well) events usually are not being emitted through **ethers** on **optimism** even though I can see they are actually emitted from the contract on etherscan. I'm using Alchemy as the RPC provider and it seems there are no outages or rate limiting on there as well.

In the below code, you can see how i wait for the events.

This only happens on Optimism. Goerli works perfectly fine.

I'm curious why this piece of code fails to receive the events sometimes. Any clue or suggestion is appreciated 🙏🙏🙏

Thanks in advance.

Code Snippet

const waitSmartContractSignature = async (signer: Signer, hash: string) => {
    const walletContract = new Contract(await signer.getAddress(), EIP1271.abi, signer)
    const internalHash = await walletContract.getMessageHash(hash)
    const eventFilter = walletContract.filters.SignMsg(internalHash)
    return await resolveOnContractEvent(walletContract, eventFilter)
}

const resolveOnContractEvent = (contract: Contract, eventFilter: EventFilter) =>
    new Promise<void>((resolve, reject) => contract.once(eventFilter, resolve).once('error', reject))


### Contract ABI

```shell
{
    "abi": [
        {
            "anonymous": false,
            "inputs": [
                {
                    "indexed": true,
                    "internalType": "bytes32",
                    "name": "msgHash",
                    "type": "bytes32"
                }
            ],
            "name": "SignMsg",
            "type": "event"
        },
        {
            "inputs": [
                {
                    "internalType": "bytes",
                    "name": "message",
                    "type": "bytes"
                }
            ],
            "name": "getMessageHash",
            "outputs": [
                {
                    "internalType": "bytes32",
                    "name": "",
                    "type": "bytes32"
                }
            ],
            "stateMutability": "view",
            "type": "function"
        },
        {
            "inputs": [
                {
                    "internalType": "bytes",
                    "name": "_data",
                    "type": "bytes"
                }
            ],
            "name": "signMessage",
            "outputs": [],
            "stateMutability": "nonpayable",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "internalType": "bytes32",
                    "name": "_hash",
                    "type": "bytes32"
                },
                {
                    "internalType": "bytes",
                    "name": "_signature",
                    "type": "bytes"
                }
            ],
            "name": "isValidSignature",
            "outputs": [
                {
                    "internalType": "bytes4",
                    "name": "",
                    "type": "bytes4"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        }
    ]
}

Errors

No response

Environment

Browser (Chrome, Safari, etc)

Environment (Other)

optimism, alchemy

Metadata

Metadata

Assignees

Labels

discussionQuestions, feedback and general information.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions