Open parva-jain opened 3 weeks ago
6.13.0
event-listener
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.
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, }) }, ) }
Insignificant here
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' }
Altcoin - Please specify (e.g. Polygon), node.js (v12 or newer)
Alt - polygon mainnet, polygon amoy, filecoin mainnet, filecoin calibration testnet
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
Contract ABI
Errors
Environment
Altcoin - Please specify (e.g. Polygon), node.js (v12 or newer)
Environment (Other)
Alt - polygon mainnet, polygon amoy, filecoin mainnet, filecoin calibration testnet