The Contract interface also have APIs to help you work with fully-typed contract events easily and smoothly.
Decode contract events from transaction events
import { ContractEvent } from'dedot/contract';// Initialize Contract instanceconstcontract=newContract<FlipperContractApi>(client, flipperMetadata, contractAddress);// Extracting contract events from transaction eventsawaitcontract.tx.flip({ gasLimit:raw.gasRequired }).signAndSend(ALICE, ({ status, events }) => {if (status.type ==='BestChainBlockIncluded'||status.type ==='Finalized') {// fully-typed eventconstflippedEvent=contract.events.Flipped.find(events);console.log('Old value',flippedEvent.data.old);console.log('New value',flippedEvent.data.new);// an array of Flipped eventconstflippedEvents=contract.events.Flipped.filter(events);// Get all contract events from current transactionsconstcontractEvents:ContractEvent[] =contract.decodeEvents(events);// Another way to get the Flipper eventconstflippedEvent2=contractEvents.find(contract.events.Flipped.is); } });
Decode contract events from system events
// Extracting contract events from system eventsawaitclient.query.system.events((events) => {// fully-typed eventconstflippedEvent=contract.events.Flipped.find(events); // or filter, is// get all events of this contract from current blockconstcontractEvents:ContractEvent[] =contract.decodeEvents(events);})