docs ⦿ dedot 🧑‍💻
TypinkXTelegramGithub
dedot 🧑‍💻
dedot 🧑‍💻
  • Welcome to Dedot
  • Why Dedot?
  • Getting started
    • Installation
    • Connect to network
    • @polkadot/api -> dedot
    • Packages structure
  • Clients & Providers
    • Providers
    • Clients
  • Client API
    • ChainApi
    • Constants
    • Runtime APIs
    • Storage Queries
    • Transactions
    • Events
    • Errors
  • ink! Smart Contracts
    • Introduction
    • Generate Types & APIs
    • Deploy contracts
    • Queries
    • Transactions
    • Events
    • Handle errors
  • CLI
  • Keyring & Signer
  • Runtime upgrades
  • Type system
  • Utilities
    • HexString
    • Uint8Array (U8a)
    • String
    • Hash functions
    • Address
    • BigInt & number
  • Help & FAQ
    • Tutorials
      • Develop ink! dApp using Typink
    • Built with Dedot
    • Forum Posts
    • Telegram
    • Github
    • API Reference
Powered by GitBook
On this page
  • Decode contract events from transaction events
  • Decode contract events from system events
  • Contract Event API

Was this helpful?

Edit on GitHub
  1. ink! Smart Contracts

Events

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 instance
const contract = new Contract<FlipperContractApi>(client, flipperMetadata, contractAddress);

// Extracting contract events from transaction events
await contract.tx.flip({ gasLimit: raw.gasRequired })
  .signAndSend(ALICE, ({ status, events }) => {
    if (status.type === 'BestChainBlockIncluded' || status.type === 'Finalized') {
      // fully-typed event
      const flippedEvent = contract.events.Flipped.find(events);
      console.log('Old value', flippedEvent.data.old);
      console.log('New value', flippedEvent.data.new);
      
      // an array of Flipped event
      const flippedEvents = contract.events.Flipped.filter(events);
      
      // Get all contract events from current transactions
      const contractEvents: ContractEvent[] = contract.decodeEvents(events);
      
      // Another way to get the Flipper event
      const flippedEvent2 = contractEvents.find(contract.events.Flipped.is);
    }
  });

Decode contract events from system events

// Extracting contract events from system events
await client.query.system.events((events) => {
  // fully-typed event
  const flippedEvent = contract.events.Flipped.find(events); // or filter, is
  
  // get all events of this contract from current block
  const contractEvents: ContractEvent[] = contract.decodeEvents(events);
})

Contract Event API

TODO

find

filter

is

meta

PreviousTransactionsNextHandle errors

Last updated 8 months ago

Was this helpful?