Universal Bridge: Transaction Approvals

Required approvals are now included in the Universal Bridge transactions response.

Universal Bridge: Transaction Approvals

You can use the transactions array returned by a Universal Bridge prepared quote to easily execute a full route from origin to destination. This pattern is now even easier with transaction action fields included to denote what each transaction does. The most important of these actions is the approval type, which represents a pre-assembled approval transaction. The approval will account for the sender's existing set allowance and what token is needed for the next step.

A quote response might look something like this:

{
  id: "0xf04cca9127820d71ab8fe588ed9532d14d61ee883bfe29870873258646d8a03e",
  originAmount: "1003793",
  destinationAmount: "1000000",
  blockNumber: "133945469",
  timestamp: 1743489718527,
  estimatedExecutionTimeMs: 62000,
  intent: {
    originChainId: 10,
    originTokenAddress: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
    destinationChainId: 8453,
    destinationTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    buyAmountWei: "1000000",
    sender: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
    receiver: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
  },
  transactions: [
    {
      chainId: 10,
      to: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
      data: "0x...",
      type: "eip1559",
      id: "0x723a578f5f04178f410da8e2029c138d4cad76900a9d9e650603fc64e56e113b",
      action: "approval",
    }, {
      to: "0x81d57DD01a15BC1C19563693902df621500D4d2A",
      value: "0",
      data: "0x...",
      chainId: 10,
      from: "0x2a4f24F935Eb178e3e7BA9B53A5Ee6d8407C0709",
      type: "eip1559",
      action: "buy",
      id: "0x3f0cb9f8a3e8649284d5c3f44648237f821c19de490fce9572509d79292867dc",
    }
  ],
}

To execute this bridge with the TypeScript SDK, use sendAndConfirmTransaction to send each transaction, and wait for a successful Bridge.status response for each non-approval transaction:

import { Bridge, sendAndConfirmTransaction } from "thirdweb";

for (const tx of preparedBuy.transactions) {
  const hash = await sendAndConfirmTransaction({
    transaction: prepareTransaction(tx),
    account, // Learn to generate a thirdweb account https://portal.thirdweb.com/connect/wallet/get-started
  });

  if (tx.action !== "approval") {
    // Wait for Bridge.status to return "COMPLETED" status
  }
}

It's that easy to implement bridging and swapping in your app. Want to get started? You can find the full API reference here.