Skip to content

[SDK] Update token price APIs to query from insight directly #7220

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

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented May 30, 2025


PR-Codex overview

This PR primarily focuses on updating the @thirdweb-dev/engine and related packages to improve API specifications, enhance error handling, and optimize fetching mechanisms for token prices and NFT data.

Detailed summary

  • Updated CHANGELOG.md for version 3.0.3.
  • Added new OpenAPI specifications for @thirdweb-dev/insight and thirdweb.
  • Changed API parameters from chain to chain_id.
  • Removed deprecated endpoints from definitions.ts.
  • Modified error handling in convertFiatToCrypto and convertCryptoToFiat functions.
  • Introduced caching for token price queries with withCache.
  • Updated several types in sdk.gen.ts and types.gen.ts to include new fields like name in webhook responses.
  • Removed unused webhook-related endpoints and improved existing ones for clarity.
  • Added new API methods for fetching token owners and tokens.

The following files were skipped due to too many changes: packages/insight/src/client/types.gen.ts

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

Summary by CodeRabbit

  • New Features
    • Added new endpoints for querying tokens and token owners by contract.
  • Improvements
    • Simplified and unified authentication for API calls.
    • Enhanced error handling for crypto/fiat conversion functions.
    • Updated token price APIs to use a new data source.
    • Deprecated older token balance endpoints in favor of newer ones.
  • Bug Fixes
    • Corrected query parameters for NFT metadata fetching.
  • Documentation
    • Updated changelogs and metadata to reflect recent changes.
  • Tests
    • Removed tests for deprecated error scenarios in conversion functions.

Copy link

vercel bot commented May 30, 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 May 30, 2025 4:35am
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 4:35am
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 4:35am
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 4:35am
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2025 4:35am

Copy link

changeset-bot bot commented May 30, 2025

🦋 Changeset detected

Latest commit: 7065da1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/insight Patch
@thirdweb-dev/wagmi-adapter Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented May 30, 2025

## Walkthrough

This update standardizes token price API calls in the "thirdweb" component to use the "insight" service, replacing previous data sources. It refactors authentication for insight endpoints, removes deprecated webhook OTP verification, adds new token-related endpoints, updates NFT query parameters, and enhances error handling in crypto/fiat conversion utilities and their tests.

## Changes

| File(s)                                                                                   | Change Summary                                                                                                                        |
|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| .changeset/fuzzy-walls-allow.md<br>.changeset/petite-falcons-ring.md                     | Added/updated changeset metadata files documenting patch updates for "thirdweb" and "insight" components.                             |
| packages/engine/CHANGELOG.md                                                             | Fixed changelog header to reference the correct package.                                                                              |
| packages/insight/src/client/sdk.gen.ts                                                   | Standardized authentication to API key headers, removed webhook OTP endpoints, added new token endpoints, deprecated old balance APIs. |
| packages/thirdweb/src/insight/get-nfts.ts                                                | Changed NFT query parameter from `chain` to `chain_id` (as an array).                                                                 |
| packages/thirdweb/src/pay/convert/cryptoToFiat.ts<br>packages/thirdweb/src/pay/convert/fiatToCrypto.ts | Replaced manual fetch calls with `getV1TokensPrice` from insight, improved error handling, updated response parsing.                  |
| packages/thirdweb/src/pay/convert/cryptoToFiat.test.ts<br>packages/thirdweb/src/pay/convert/fiatToCrypto.test.ts | Removed tests for failed fetch responses and unused imports.                                                                          |
| packages/thirdweb/src/pay/utils/definitions.ts                                           | Removed deprecated functions returning fiat/crypto conversion endpoint URLs.                                                          |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Client
    participant Thirdweb
    participant InsightAPI

    Client->>Thirdweb: convertCryptoToFiat(token, amount, chain)
    Thirdweb->>InsightAPI: getV1TokensPrice(token, chain_id)
    InsightAPI-->>Thirdweb: token price data
    Thirdweb-->>Client: fiat value (amount * price_usd)
sequenceDiagram
    participant Client
    participant Thirdweb
    participant InsightAPI

    Client->>Thirdweb: convertFiatToCrypto(token, amount, chain)
    Thirdweb->>InsightAPI: getV1TokensPrice(token, chain_id)
    InsightAPI-->>Thirdweb: token price data
    Thirdweb-->>Client: crypto amount (amount / price_usd)
Loading

Possibly related PRs

Suggested reviewers

  • MananTank

<!-- walkthrough_end -->

<!-- This is an auto-generated comment: resource warnings by coderabbit.ai -->

> [!WARNING]
> ## Review ran into problems
> 
> <details>
> <summary>🔥 Problems</summary>
> 
> Errors were encountered while retrieving linked issues.
> 
> <details>
> <summary>Errors (1)</summary>
> 
> * TEAM-0000: Entity not found: Issue - Could not find referenced Issue.
> 
> </details>
> 
> </details>

<!-- end of auto-generated comment: resource warnings by coderabbit.ai -->

---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between a68be7be561da138ff9c45faf308a996e9bc4344 and 7065da159dd8ee88dfd03ed1e86d4aaf0eab7c6e.

</details>

<details>
<summary>📒 Files selected for processing (10)</summary>

* `.changeset/fuzzy-walls-allow.md` (1 hunks)
* `.changeset/petite-falcons-ring.md` (1 hunks)
* `packages/engine/CHANGELOG.md` (1 hunks)
* `packages/insight/src/client/sdk.gen.ts` (15 hunks)
* `packages/thirdweb/src/insight/get-nfts.ts` (1 hunks)
* `packages/thirdweb/src/pay/convert/cryptoToFiat.test.ts` (1 hunks)
* `packages/thirdweb/src/pay/convert/cryptoToFiat.ts` (2 hunks)
* `packages/thirdweb/src/pay/convert/fiatToCrypto.test.ts` (1 hunks)
* `packages/thirdweb/src/pay/convert/fiatToCrypto.ts` (2 hunks)
* `packages/thirdweb/src/pay/utils/definitions.ts` (0 hunks)

</details>

<details>
<summary>💤 Files with no reviewable changes (1)</summary>

* packages/thirdweb/src/pay/utils/definitions.ts

</details>

<details>
<summary>✅ Files skipped from review due to trivial changes (1)</summary>

* packages/thirdweb/src/pay/convert/cryptoToFiat.test.ts

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (8)</summary>

* packages/engine/CHANGELOG.md
* .changeset/fuzzy-walls-allow.md
* .changeset/petite-falcons-ring.md
* packages/thirdweb/src/insight/get-nfts.ts
* packages/thirdweb/src/pay/convert/fiatToCrypto.test.ts
* packages/thirdweb/src/pay/convert/cryptoToFiat.ts
* packages/thirdweb/src/pay/convert/fiatToCrypto.ts
* packages/insight/src/client/sdk.gen.ts

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (8)</summary>

* GitHub Check: E2E Tests (pnpm, esbuild)
* GitHub Check: Size
* GitHub Check: E2E Tests (pnpm, webpack)
* GitHub Check: Build Packages
* GitHub Check: E2E Tests (pnpm, vite)
* GitHub Check: Lint Packages
* GitHub Check: Unit Tests
* GitHub Check: Analyze (javascript)

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNxU3bABsvkCiQBHbGlcSHFcLzpIACIAbQBlABEAaQBdSABVblpqEjD8AGsyHgp4BjyAQSsASWQCSCDKeQAzChYUDER4IlhQ2nh/MS9ZaMg5SGxESkghfDQg+GYwKQpSZAAKW0gzAHYAJj2ABgBKSGb8BknpfixsbOp4DCIw2DyCIqxeMsqayDJabj4R64ZAAd3UCCwuFekAABtCBrRQSQBLDIElkvkGsEXJAcrg0HiBqIIi02swXnlqp1ur17JQJN8NDAYQxYJg1h0GF5sEoJtwiFR+k9KXCAAIIihIlFgJQSAD0Z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5Yu2rbXXIkvctIVvXAt8vv7gFPA9Fxh+gjp6vZ30BrQvZLSKOPgAByZAexubvBF0aZvLFHLAQQEQMQR1uEY7pC43GcWQRpqQjp7GNtkWjtnjLt7pudNypZ7QqAIZyFkZ2mMZ1p856ZotGWGEZyyDG6psBFmcXdlFtECsdkkuvyl5gQTW7r7W7sFJGK+d/d7TRMQc5Wp5sd7exnkKiTrceUI08iqrRdvTYF9c1d8Fz9Td6FynP4SW9eknjsCeqwbrzqTZin7Z89Sp4EU+iVwojX2QLX+27Zsq3APXxiA3zH4mjj1zmEEKbwBD14VqjO5AVXRsdXOAtrox5uy9FTvWagF9wgN9hcV+7Z0PrlGKj9yowLNggCZq0xKQYYRmrhMzZCHcNGJAHL0DjsLWVmu32aJQJtgdFtmQ1prjKH0aBHzIpHxZ/psTKAPQ2zU47pjOrgdXzXndtnvdhca37/dYUYutGn+D558dhnt5oKpnoXvdUXvLcXh4nQ1vgwpX7tzvvDk3s3mcFFy3wfp7YfqnrAMf3dPnyc6frWufkXnLMX9jTn7n6JWJNRJboKdxaXvRHxAxPwNAAJNd+QEJFYhUBqAIk9iJ/o4nkTqAsKiAWMAU1/DIhaAsYBhIm2UQGAIBaAAAGwAAOXmDsF5gH4MBG+HIBvkNBYDG0AATgYCHUD83KZoIaEOBYC0A5A8gRgJIDkCBAVAw0IdUOpRJDAEAnYIcAwEH5iBB+cgaRCwGcQsBWA2gM0FoCHBDQdADfCQCwEYDaAh1NAGgGaCHByEAgHYAwFYG8Dn+kA3ANANgHPJ4BdAWMOon0BAA=== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=thirdweb-dev/js&utm_content=7220):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels May 30, 2025
Copy link
Member Author


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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@joaquim-verges joaquim-verges changed the title Update token price APIs to query from insight directly [SDK] Update token price APIs to query from insight directly May 30, 2025
@joaquim-verges joaquim-verges marked this pull request as ready for review May 30, 2025 01:10
@joaquim-verges joaquim-verges requested review from a team as code owners May 30, 2025 01:10
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
packages/insight/src/client/sdk.gen.ts (1)

1-1172: 🛠️ Refactor suggestion

Overall assessment: Well-structured API evolution with breaking changes.

The changes represent a significant but well-planned API evolution:

Positives:

  • Consistent authentication model (x-secret-key for webhooks, x-client-id for others)
  • Proper deprecation strategy with backward compatibility
  • New token functionality enhances API capabilities
  • Code follows established patterns and conventions

Critical considerations:

  • Breaking authentication changes require migration support
  • Deprecated endpoints need clear migration paths
  • Documentation should be updated to reflect all changes

Ensure comprehensive migration documentation is provided for the authentication changes and deprecated endpoints to minimize disruption to existing users.

🧹 Nitpick comments (2)
packages/thirdweb/src/pay/convert/cryptoToFiat.ts (1)

98-121: Consider adding zero price validation for consistency.

The refactoring to use getV1TokensPrice is well-implemented with proper error handling and response parsing. However, there's an inconsistency with the fiatToCrypto.ts implementation.

Apply this diff to add zero price validation for consistency with fiatToCrypto.ts:

-  if (!firstResult) {
+  if (!firstResult || firstResult.price_usd === 0) {
     throw new Error(
       `Failed to fetch ${to} value for token (${fromTokenAddress}) on chainId: ${chain.id}`,
     );
   }

This ensures that tokens with zero USD price are handled consistently across both conversion functions.

packages/insight/src/client/sdk.gen.ts (1)

524-527: LGTM! Proper deprecation strategy with new tokens endpoint.

The deprecation of getV1TokensErc20ByOwnerAddress in favor of the new getV1Tokens endpoint follows good practices by maintaining backward compatibility while guiding users to the new API.

Consider providing migration examples in documentation showing how to transition from the deprecated ERC-20 specific endpoint to the new general tokens endpoint.

Also applies to: 549-570

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 819ce86 and a68be7b.

📒 Files selected for processing (9)
  • .changeset/fuzzy-walls-allow.md (1 hunks)
  • .changeset/petite-falcons-ring.md (1 hunks)
  • packages/engine/CHANGELOG.md (1 hunks)
  • packages/insight/src/client/sdk.gen.ts (15 hunks)
  • packages/thirdweb/src/insight/get-nfts.ts (1 hunks)
  • packages/thirdweb/src/pay/convert/cryptoToFiat.test.ts (1 hunks)
  • packages/thirdweb/src/pay/convert/cryptoToFiat.ts (2 hunks)
  • packages/thirdweb/src/pay/convert/fiatToCrypto.test.ts (1 hunks)
  • packages/thirdweb/src/pay/convert/fiatToCrypto.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/insight/src/client/sdk.gen.ts (1)
packages/insight/src/client/types.gen.ts (6)
  • GetV1TokensOwnersData (1740-1763)
  • GetV1TokensOwnersResponse (1800-1800)
  • GetV1TokensOwnersError (1784-1784)
  • GetV1TokensTransfersData (2014-2065)
  • GetV1TokensData (2199-2238)
  • GetV1TokensResponse (2270-2270)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Unit Tests
  • GitHub Check: Size
🔇 Additional comments (13)
packages/engine/CHANGELOG.md (1)

1-1: LGTM! Correct package name in changelog header.

This properly fixes the changelog header to reference the correct package name.

.changeset/fuzzy-walls-allow.md (1)

1-6: LGTM! Properly formatted changeset documentation.

The changeset correctly documents the patch update for the thirdweb package with an appropriate description.

.changeset/petite-falcons-ring.md (1)

1-6: LGTM! Properly formatted changeset documentation.

The changeset correctly documents the patch update for the insight package with an appropriate description.

packages/thirdweb/src/pay/convert/cryptoToFiat.test.ts (1)

1-1: LGTM! Import cleanup aligns with refactoring.

The removal of the vi import is consistent with the shift away from manual fetch mocking to using the insight SDK directly.

packages/thirdweb/src/pay/convert/fiatToCrypto.test.ts (1)

1-1: LGTM! Import cleanup aligns with refactoring.

The removal of the vi import is consistent with the shift away from manual fetch mocking to using the insight SDK directly.

packages/thirdweb/src/pay/convert/fiatToCrypto.ts (2)

1-1: LGTM! Updated imports for insight SDK integration.

The new imports properly support the refactoring to use the insight service directly instead of manual fetch calls.

Also applies to: 9-11


96-119: LGTM! Well-implemented insight SDK integration with robust error handling.

The refactoring to use getV1TokensPrice from the insight SDK is well-executed:

  • Proper configuration with base URL and client fetch
  • Enhanced error handling that includes HTTP status and detailed error information
  • Defensive programming with checks for valid response data and non-zero price
  • Correct conversion calculation (fiat amount divided by USD price)

The implementation maintains the same function behavior while improving the underlying data source and error reporting.

packages/thirdweb/src/pay/convert/cryptoToFiat.ts (1)

1-1: LGTM! Updated imports for insight SDK integration.

The new imports properly support the refactoring to use the insight service directly instead of manual fetch calls.

Also applies to: 9-11

packages/insight/src/client/sdk.gen.ts (5)

72-72: LGTM! New token-related type imports.

The new imports properly support the added token and token owners endpoints.

Also applies to: 81-83, 88-88


169-169: LGTM! Webhook descriptions updated to reflect removed OTP functionality.

The descriptions now correctly reflect the current webhook functionality without the deprecated OTP verification features.

Also applies to: 221-221


424-445: LGTM! New token owners endpoint properly implemented.

The getV1TokensOwners function follows established patterns and uses consistent authentication with other non-webhook endpoints.


501-507: LGTM! Token transfers endpoint made more flexible.

The changes make the options parameter optional and update the description to reflect broader functionality. The implementation is consistent with other optional parameter functions.

Verify that the API endpoint now supports general token transfers queries without requiring specific wallet address parameters.


869-870: LGTM! NFT endpoints updated consistently.

The changes to NFT endpoints follow the same patterns as token endpoints - simplified descriptions and optional parameters for increased flexibility.

Also applies to: 942-948

@@ -213,7 +213,7 @@ export async function getNFT(args: {

const defaultQueryOptions: GetV1NftsByContractAddressByTokenIdData["query"] =
{
chain: chain.id,
chain_id: [chain.id],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify consistency of query parameter formats across similar functions.

The parameter change from chain: chain.id to chain_id: [chain.id] looks correct and aligns with the API updates. However, other functions in this file still use the chain parameter format (lines 59, 136). Please verify that this inconsistency is intentional due to different endpoint requirements.


🏁 Script executed:

#!/bin/bash
# Verify the query parameter consistency across similar insight API calls
echo "Checking for chain/chain_id parameter usage patterns in insight-related files:"
rg -A 3 -B 3 "chain(_id)?:" packages/thirdweb/src/insight/

echo -e "\nChecking insight SDK types for expected parameter formats:"
rg -A 5 -B 2 "chain_id|chain.*:" packages/insight/ || echo "Insight package files not available for verification"

Length of output: 71155


Ensure consistent use of chain_id across all Insight queries

According to the Insight SDK types, the chain parameter is now deprecated in favor of chain_id (an array of IDs). While getNFT has been updated, the other query builders in get-nfts.ts still use the old chain field. Please update them to match:

• packages/thirdweb/src/insight/get-nfts.ts
– In the defaultQueryOptions for fetching all NFTs (GetV1NftsData), change:
diff - chain: chains.map((chain) => chain.id), + chain_id: chains.map((chain) => chain.id),
• packages/thirdweb/src/insight/get-nfts.ts
– In the defaultQueryOptions for fetching NFTs by contract address (GetV1NftsByContractAddressData), apply the same replacement.

This will align every Insight endpoint with the new API spec and avoid relying on deprecated parameters.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/thirdweb/src/insight/get-nfts.ts around lines 59 and 136, update the
query parameter from the deprecated 'chain' to 'chain_id' as an array of IDs,
similar to the change made at line 216. Replace all instances of 'chain:
chain.id' with 'chain_id: [chain.id]' in the defaultQueryOptions for fetching
all NFTs and for fetching NFTs by contract address to ensure consistency with
the Insight SDK's current API specification.

{
in: "query",
name: "clientId",
name: "x-secret-key",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Breaking change: Webhook authentication mechanism updated.

All webhook endpoints now use x-secret-key API key authentication instead of the previous bearer token approach. This is a breaking change that will require users to update their webhook authentication.

Ensure that:

  1. Migration documentation is provided for existing webhook users
  2. The new authentication mechanism is properly documented
  3. Backward compatibility considerations have been addressed

Also applies to: 181-181, 210-210, 235-235, 262-262


🏁 Script executed:

#!/bin/bash
# Check if there are any references to the old bearer authentication in documentation
rg -i "bearer.*webhook|webhook.*bearer" --type md --type txt

Length of output: 62


🏁 Script executed:

#!/bin/bash
# Broadly search for any mention of the old bearer auth in docs
rg -i "bearer" --type md --type txt -A 2

# Search for the new x-secret-key usage in docs to confirm documentation was updated
rg -i "x-secret-key" --type md --type txt -A 2

Length of output: 444


Breaking change: Webhook authentication switched to x-secret-key

Documentation still references the old Bearer-token approach but lacks any mention of the new header. Before merging, please:

• Add migration guidance for existing users (e.g. “replace Authorization: Bearer <token> with x-secret-key: <your-secret>”).
• Update docs to remove or mark deprecated all Bearer examples (found in AGENTS.md and apps/portal/public/llms-full.txt).
• Include examples and parameter descriptions for the new x-secret-key header.
• Consider a deprecation window or backward-compatibility layer if needed.

Files to update:

  • AGENTS.md
  • apps/portal/public/llms-full.txt
  • Any other Markdown/text docs with “Bearer”
🤖 Prompt for AI Agents
In packages/insight/src/client/sdk.gen.ts at lines 158, 181, 210, 235, and 262,
update the webhook authentication header from the old Bearer token to the new
"x-secret-key" header. Additionally, update all relevant documentation files
including AGENTS.md and apps/portal/public/llms-full.txt to remove or mark
deprecated the Bearer token usage, add migration instructions for users to
switch from "Authorization: Bearer <token>" to "x-secret-key: <your-secret>",
and include examples and parameter descriptions for the new header. Consider
adding a deprecation notice or backward compatibility if necessary before
finalizing the changes.

Copy link

codecov bot commented May 30, 2025

Codecov Report

Attention: Patch coverage is 78.94737% with 12 lines in your changes missing coverage. Please review.

Project coverage is 55.62%. Comparing base (f2e8b9e) to head (7065da1).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/thirdweb/src/pay/convert/cryptoToFiat.ts 78.57% 6 Missing ⚠️
packages/thirdweb/src/pay/convert/fiatToCrypto.ts 78.57% 5 Missing and 1 partial ⚠️

❌ Your patch status has failed because the patch coverage (78.94%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7220      +/-   ##
==========================================
- Coverage   55.63%   55.62%   -0.02%     
==========================================
  Files         908      908              
  Lines       58546    58570      +24     
  Branches     4128     4133       +5     
==========================================
+ Hits        32572    32577       +5     
- Misses      25868    25886      +18     
- Partials      106      107       +1     
Flag Coverage Δ
packages 55.62% <78.94%> (-0.02%) ⬇️
Files with missing lines Coverage Δ
packages/thirdweb/src/insight/get-nfts.ts 88.84% <100.00%> (ø)
packages/thirdweb/src/pay/utils/definitions.ts 38.46% <ø> (-32.13%) ⬇️
packages/thirdweb/src/pay/convert/cryptoToFiat.ts 87.87% <78.57%> (-12.13%) ⬇️
packages/thirdweb/src/pay/convert/fiatToCrypto.ts 87.50% <78.57%> (-12.50%) ⬇️
🚀 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