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
    • Balances
    • Merkleized Metadata
  • Help & FAQ
    • Tutorials
      • Develop ink! dApp using Typink
    • Built with Dedot
    • Forum Posts
    • Telegram
    • Github
    • API Reference
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. ink! Smart Contracts

Transactions

Similarly to query contracts, the Contract interface will also be using to submitting transactions with syntax: contract.tx.<message>.

import { Contract } from 'dedot/contract';
import { FlipperContractApi } from './flipper';
import flipperMetadata from './flipper.json' assert { type: 'json' };

// ... initializing DedotClient

const ALICE = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'; // Alice
const contractAddress = '...';

// create a contract instace from its metadata & address
const contract = new Contract<FlipperContractApi>(client, flipperMetadata, contractAddress);

// Dry-run the call for validation and gas estimation
const { data, raw } = await contract.query.flip({ caller: ALICE });

// Check if the message return a `Result<Data, Error>`
// Skip this check if the message returning raw Data
if (data.isErr) {
  console.log('Cannot make transaction due to error:', data.err);
}

// Submitting the transaction after passing validation
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);
    }
  })
PreviousQueriesNextEvents

Last updated 8 months ago

Was this helpful?