Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version Packages #6504

Merged
merged 1 commit into from
Mar 21, 2025
Merged

Version Packages #6504

merged 1 commit into from
Mar 21, 2025

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Mar 20, 2025

This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.

Releases

[email protected]

Minor Changes

  • #6464 654f879 Thanks @gregfromstl! - Adds a new Bridge module to the thirdweb SDK to access the Universal Bridge.

    Features

    Buy & Sell Operations

    The Bridge module makes it easy to buy and sell tokens across chains:

    • Bridge.Buy - For specifying the destination amount you want to receive
    • Bridge.Sell - For specifying the origin amount you want to send

    Each operation provides two functions:

    1. quote - Get an estimate without connecting a wallet
    2. prepare - Get a finalized quote with transaction data

    Buy Example

    import { Bridge, toWei, NATIVE_TOKEN_ADDRESS } from "thirdweb";
    
    // First, get a quote to see approximately how much you'll pay
    const buyQuote = await Bridge.Buy.quote({
      originChainId: 1, // Ethereum
      originTokenAddress: NATIVE_TOKEN_ADDRESS,
      destinationChainId: 10, // Optimism
      destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
      buyAmountWei: toWei("0.01"), // I want to receive 0.01 ETH on Optimism
      client: thirdwebClient,
    });
    
    console.log(
      `To get ${buyQuote.destinationAmount} wei on destination chain, you need to pay ${buyQuote.originAmount} wei`,
    );
    
    // When ready to execute, prepare the transaction
    const preparedBuy = await Bridge.Buy.prepare({
      originChainId: 1,
      originTokenAddress: NATIVE_TOKEN_ADDRESS,
      destinationChainId: 10,
      destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
      buyAmountWei: toWei("0.01"),
      sender: "0x...", // Your wallet address
      receiver: "0x...", // Recipient address (can be the same as sender)
      client: thirdwebClient,
    });
    
    // The prepared quote contains the transactions you need to execute
    console.log(`Transactions to execute: ${preparedBuy.transactions.length}`);

    Sell Example

    import { Bridge, toWei } from "thirdweb";
    
    // First, get a quote to see approximately how much you'll receive
    const sellQuote = await Bridge.Sell.quote({
      originChainId: 1, // Ethereum
      originTokenAddress: NATIVE_TOKEN_ADDRESS,
      destinationChainId: 10, // Optimism
      destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
      sellAmountWei: toWei("0.01"), // I want to sell 0.01 ETH from Ethereum
      client: thirdwebClient,
    });
    
    console.log(
      `If you send ${sellQuote.originAmount} wei, you'll receive approximately ${sellQuote.destinationAmount} wei`,
    );
    
    // When ready to execute, prepare the transaction
    const preparedSell = await Bridge.Sell.prepare({
      originChainId: 1,
      originTokenAddress: NATIVE_TOKEN_ADDRESS,
      destinationChainId: 10,
      destinationTokenAddress: NATIVE_TOKEN_ADDRESS,
      sellAmountWei: toWei("0.01"),
      sender: "0x...", // Your wallet address
      receiver: "0x...", // Recipient address (can be the same as sender)
      client: thirdwebClient,
    });
    
    // Execute the transactions in sequence
    for (const tx of preparedSell.transactions) {
      // Send the transaction using your wallet
      // Wait for it to be mined
    }

    Bridge Routes

    You can discover available bridge routes using the routes function:

    import { Bridge, NATIVE_TOKEN_ADDRESS } from "thirdweb";
    
    // Get all available routes
    const allRoutes = await Bridge.routes({
      client: thirdwebClient,
    });
    
    // Filter routes for a specific token or chain
    const filteredRoutes = await Bridge.routes({
      originChainId: 1, // From Ethereum
      originTokenAddress: NATIVE_TOKEN_ADDRESS,
      destinationChainId: 10, // To Optimism
      client: thirdwebClient,
    });
    
    // Paginate through routes
    const paginatedRoutes = await Bridge.routes({
      limit: 10,
      offset: 0,
      client: thirdwebClient,
    });

    Bridge Transaction Status

    After executing bridge transactions, you can check their status:

    import { Bridge } from "thirdweb";
    
    // Check the status of a bridge transaction
    const bridgeStatus = await Bridge.status({
      transactionHash:
        "0xe199ef82a0b6215221536e18ec512813c1aa10b4f5ed0d4dfdfcd703578da56d",
      chainId: 8453, // The chain ID where the transaction was initiated
      client: thirdwebClient,
    });
    
    // The status will be one of: "COMPLETED", "PENDING", "FAILED", or "NOT_FOUND"
    if (bridgeStatus.status === "completed") {
      console.log(`
        Bridge completed!
        Sent: ${bridgeStatus.originAmount} wei on chain ${bridgeStatus.originChainId}
        Received: ${bridgeStatus.destinationAmount} wei on chain ${bridgeStatus.destinationChainId}
      `);
    } else if (bridgeStatus.status === "pending") {
      console.log("Bridge transaction is still pending...");
    } else {
      console.log("Bridge transaction failed");
    }

    Error Handling

    The Bridge module provides consistent error handling with descriptive error messages:

    try {
      await Bridge.Buy.quote({
        // ...params
      });
    } catch (error) {
      // Errors will have the format: "ErrorCode | Error message details"
      console.error(error.message); // e.g. "AmountTooHigh | The provided amount is too high for the requested route."
    }

    Types

    The Bridge module exports the following TypeScript types:

    • Route - Describes a bridge route between chains and tokens
    • Status - Represents the status of a bridge transaction
    • Quote - Contains quote information for a bridge transaction
    • PreparedQuote - Extends Quote with transaction data

    Integration

    The Bridge module is accessible as a top-level export:

    import { Bridge } from "thirdweb";

    Use Bridge.Buy, Bridge.Sell, Bridge.routes, and Bridge.status to access the corresponding functionality.

Patch Changes

@thirdweb-dev/[email protected]


PR-Codex overview

This PR primarily updates the versions of the @thirdweb-dev/wagmi-adapter and thirdweb packages, introduces a new Bridge module for token operations, and enhances the changelog documentation with examples and error handling.

Detailed summary

  • Updated @thirdweb-dev/wagmi-adapter version from 0.2.34 to 0.2.35.
  • Updated thirdweb version from 5.92.3 to 5.93.0.
  • Added a new Bridge module for cross-chain token operations.
  • Documented Bridge.Buy and Bridge.Sell functionalities with examples.
  • Included error handling for bridge transactions.
  • Enhanced changelog with minor changes and patch updates.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@joaquim-verges joaquim-verges requested review from a team as code owners March 20, 2025 07:09
Copy link

vercel bot commented Mar 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2025 10:01pm
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2025 10:01pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2025 10:01pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2025 10:01pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2025 10:01pm

Copy link
Contributor

graphite-app bot commented Mar 20, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link
Contributor

github-actions bot commented Mar 20, 2025

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 47.56 KB (0%) 952 ms (0%) 107 ms (+269.11% 🔺) 1.1 s
thirdweb (cjs) 127.31 KB (0%) 2.6 s (0%) 149 ms (+81.89% 🔺) 2.7 s
thirdweb (minimal + tree-shaking) 5.6 KB (0%) 113 ms (0%) 62 ms (+2251.72% 🔺) 174 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 40 ms (+5438.43% 🔺) 50 ms
thirdweb/react (minimal + tree-shaking) 19.34 KB (0%) 387 ms (0%) 78 ms (+1026.91% 🔺) 465 ms

Copy link

codecov bot commented Mar 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.95%. Comparing base (d854021) to head (e509112).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6504      +/-   ##
==========================================
- Coverage   54.96%   54.95%   -0.01%     
==========================================
  Files         881      881              
  Lines       55148    55148              
  Branches     3767     3765       -2     
==========================================
- Hits        30311    30306       -5     
- Misses      24742    24747       +5     
  Partials       95       95              
Flag Coverage Δ
packages 54.95% <ø> (-0.01%) ⬇️

see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant