Polkadot Apps
    Preparing search index...

    Function extractTransaction

    • Validate an Ink SDK dry-run result and extract the submittable transaction.

      Replaces the 5-10 line boilerplate that every contract interaction repeats: check success, parse the error, verify send() exists, and call it.

      Works with any object whose shape matches the Ink SDK contract query result (typed structurally — no Ink SDK import required):

      • contract.query("method", { origin, data }) (Ink SDK)
      • contract.write("method", args, origin) (patched SDK wrappers)
      • Any object with { success: boolean; value?: { send?(): ... } }

      Parameters

      • result: { error?: unknown; success: boolean; value?: unknown }

        The dry-run result from a contract query or write simulation.

      Returns SubmittableTransaction

      The submittable transaction, ready to pass to submitAndWatch.

      If the dry run failed or the result has no send().

      import { extractTransaction, submitAndWatch, createDevSigner } from "@polkadot-apps/tx";

      const dryRun = await contract.query("createItem", { origin, data: { name, price } });
      const tx = extractTransaction(dryRun);
      const result = await submitAndWatch(tx, createDevSigner("Alice"));
      const tx = extractTransaction(await contract.query("transfer", { origin, data }));
      const result = await withRetry(() => submitAndWatch(tx, signer));