Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple execution of event-listener's call back function #4828

Open
parva-jain opened this issue Sep 6, 2024 · 0 comments
Open

Multiple execution of event-listener's call back function #4828

parva-jain opened this issue Sep 6, 2024 · 0 comments
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@parva-jain
Copy link

Ethers Version

6.13.0

Search Terms

event-listener

Describe the Problem

I have written an event listener that listens to the smart contract event - ReceivedToken. However the callback function of the event listener is executed multiple times on the single event emission.

Code Snippet

export default async (contract: ethers.Contract, provider: ethers.JsonRpcProvider) => {
  const { chainId } = await provider.getNetwork()
 
  contract.on(
    'ReceivedToken',
    async (tokenAddress: string, sender: string, amount: number, purchase: boolean, timestamp: number, data: any) => {
      console.log('Received Funds In Endowment Pool')

      console.log({
        tokenAddress,
        sender,
        amount: Number(amount),
        purchase,
        timestamp,
        txHash: data.log.transactionHash,
      })
    },
  )
}

Contract ABI

Insignificant here

Errors

Im getting multiple logs which shouldn't happen

Received Funds In Endowment Pool
{
  tokenAddress: '0x0000000000000000000000000000000000000000',
  sender: '0x0035cd0CA79A5b156d5443b698655DBDc5403B45',
  amount: 33404937000000000,
  purchase: true,
  timestamp: 1725608730n,
  txHash: '0xa22f31ae4d4e7c69efdc201f0e1d4e05e86b36307f22c6aecbe832180bc16c1b'
}
Received Funds In Endowment Pool
{
  tokenAddress: '0x0000000000000000000000000000000000000000',
  sender: '0x0035cd0CA79A5b156d5443b698655DBDc5403B45',
  amount: 33404937000000000,
  purchase: true,
  timestamp: 1725608730n,
  txHash: '0xa22f31ae4d4e7c69efdc201f0e1d4e05e86b36307f22c6aecbe832180bc16c1b'
}
Received Funds In Endowment Pool
{
  tokenAddress: '0x0000000000000000000000000000000000000000',
  sender: '0x0035cd0CA79A5b156d5443b698655DBDc5403B45',
  amount: 33404937000000000,
  purchase: true,
  timestamp: 1725608730n,
  txHash: '0xa22f31ae4d4e7c69efdc201f0e1d4e05e86b36307f22c6aecbe832180bc16c1b'
}
Received Funds In Endowment Pool
{
  tokenAddress: '0x0000000000000000000000000000000000000000',
  sender: '0x0035cd0CA79A5b156d5443b698655DBDc5403B45',
  amount: 33404937000000000,
  purchase: true,
  timestamp: 1725608730n,
  txHash: '0xa22f31ae4d4e7c69efdc201f0e1d4e05e86b36307f22c6aecbe832180bc16c1b'
}
Received Funds In Endowment Pool
{
  tokenAddress: '0x0000000000000000000000000000000000000000',
  sender: '0x0035cd0CA79A5b156d5443b698655DBDc5403B45',
  amount: 33404937000000000,
  purchase: true,
  timestamp: 1725608730n,
  txHash: '0xa22f31ae4d4e7c69efdc201f0e1d4e05e86b36307f22c6aecbe832180bc16c1b'
}

Environment

Altcoin - Please specify (e.g. Polygon), node.js (v12 or newer)

Environment (Other)

Alt - polygon mainnet, polygon amoy, filecoin mainnet, filecoin calibration testnet

@parva-jain parva-jain added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

2 participants