Skip to content

[SDK] Feature: Adds explicit country param to onramps #7185

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

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clear-books-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Adds `country` to onramp parameters
23 changes: 23 additions & 0 deletions packages/thirdweb/src/bridge/Onramp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
maxSteps?: number;
excludeChainIds?: string;
paymentLinkId?: string;
country?: string;
}

/**
Expand Down Expand Up @@ -107,6 +108,22 @@
* }
* ```
*
* ### Global Support
*
* For the best user experience, specify the user's `country` code in your request. This will return an error if the user's country is not supported by the provider.
*
* ```typescript
* const preparedOnramp = await Bridge.Onramp.prepare({
* client: thirdwebClient,
* onramp: "stripe",
* chainId: ethereum.id,
* tokenAddress: NATIVE_TOKEN_ADDRESS,
* receiver: "0x...", // receiver's address
* amount: toWei("10"), // 10 of the destination token
* country: "AU" // User's country code
* });
* ```
*
* @param options - The options for preparing the onramp.
* @param options.client - Your thirdweb client.
* @param options.onramp - The onramp provider to use (e.g., "stripe", "coinbase", "transak").
Expand All @@ -121,6 +138,7 @@
* @param [options.currency] - The currency for the onramp (e.g., "USD", "GBP"). Defaults to user's preferred or "USD".
* @param [options.maxSteps] - Maximum number of post-onramp steps.
* @param [options.excludeChainIds] - Chain IDs to exclude from the route (string or array of strings).
* @param [options.country] - The user's country code (e.g. "US", "JP"). Defaults to "US". We highly recommend this be set (based on the user's IP address).
*
* @returns A promise that resolves to the prepared onramp details, including the link and quote.
* @throws Will throw an error if there is an issue preparing the onramp.
Expand All @@ -145,6 +163,7 @@
maxSteps,
excludeChainIds,
paymentLinkId,
country,
} = options;

const clientFetch = getClientFetch(client);
Expand Down Expand Up @@ -186,6 +205,9 @@
if (paymentLinkId !== undefined) {
apiRequestBody.paymentLinkId = paymentLinkId;
}
if (country !== undefined) {
apiRequestBody.country = country;
}

Check warning on line 210 in packages/thirdweb/src/bridge/Onramp.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/bridge/Onramp.ts#L209-L210

Added lines #L209 - L210 were not covered by tests

const response = await clientFetch(url, {
method: "POST",
Expand Down Expand Up @@ -247,6 +269,7 @@
currency?: string;
maxSteps?: number;
excludeChainIds?: string | string[];
country?: string;
/**
* @hidden
*/
Expand Down
Loading