Events

Events

You can subscribe to events using useFlowEvent:

import { useFlowEvent } from '@doodlesteam/flooks';
 
interface TokensWithdrawnData {
  amount: string;
  from: string
};
 
function Component {
  useFlowEvent<TokensWithdrawnData>({
    eventName: {
      contractAddress: '0x7e60df042a9c0868', // Flooks will automatically remove the '0x' prefix
      contractName: 'FlowToken',
      eventName: 'TokensWithdrawn',
    },
    listener: (event: TokensWithdrawnData) => {
      console.log('TokensWithdrawn', event.amount, event.from);
    },
  });
 
  // Rest of the code...
}

You can also pass the eventName argument as a string like fcl:

eventName: 'A.7e60df042a9c0868.FlowToken.TokensWithdrawn',

Are you waiting just for the first event emitted? Use the once argument:

import { useFlowEvent } from '@doodlesteam/flooks';
 
function Component {
  useFlowEvent<{winner: string}>({
    eventName: {
      contractAddress: '...',
      contractName: 'Auction',
      eventName: 'ClosedAuction',
    },
    once: true,
    listener: (event) => {
      // This will only be executed once
      console.log('Winner address', event.winner);
    },
  });
 
  // Rest of the code...
}