Skip to content

Commit 41e59a9

Browse files
authored
[SDK] Feature: Adds explicit country param to onramps (#7185)
1 parent fd97406 commit 41e59a9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.changeset/clear-books-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Adds `country` to onramp parameters

packages/thirdweb/src/bridge/Onramp.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ interface OnrampApiRequestBody {
5353
maxSteps?: number;
5454
excludeChainIds?: string;
5555
paymentLinkId?: string;
56+
country?: string;
5657
}
5758

5859
/**
@@ -107,6 +108,22 @@ interface OnrampApiRequestBody {
107108
* }
108109
* ```
109110
*
111+
* ### Global Support
112+
*
113+
* 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.
114+
*
115+
* ```typescript
116+
* const preparedOnramp = await Bridge.Onramp.prepare({
117+
* client: thirdwebClient,
118+
* onramp: "stripe",
119+
* chainId: ethereum.id,
120+
* tokenAddress: NATIVE_TOKEN_ADDRESS,
121+
* receiver: "0x...", // receiver's address
122+
* amount: toWei("10"), // 10 of the destination token
123+
* country: "AU" // User's country code
124+
* });
125+
* ```
126+
*
110127
* @param options - The options for preparing the onramp.
111128
* @param options.client - Your thirdweb client.
112129
* @param options.onramp - The onramp provider to use (e.g., "stripe", "coinbase", "transak").
@@ -121,6 +138,7 @@ interface OnrampApiRequestBody {
121138
* @param [options.currency] - The currency for the onramp (e.g., "USD", "GBP"). Defaults to user's preferred or "USD".
122139
* @param [options.maxSteps] - Maximum number of post-onramp steps.
123140
* @param [options.excludeChainIds] - Chain IDs to exclude from the route (string or array of strings).
141+
* @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).
124142
*
125143
* @returns A promise that resolves to the prepared onramp details, including the link and quote.
126144
* @throws Will throw an error if there is an issue preparing the onramp.
@@ -145,6 +163,7 @@ export async function prepare(
145163
maxSteps,
146164
excludeChainIds,
147165
paymentLinkId,
166+
country,
148167
} = options;
149168

150169
const clientFetch = getClientFetch(client);
@@ -186,6 +205,9 @@ export async function prepare(
186205
if (paymentLinkId !== undefined) {
187206
apiRequestBody.paymentLinkId = paymentLinkId;
188207
}
208+
if (country !== undefined) {
209+
apiRequestBody.country = country;
210+
}
189211

190212
const response = await clientFetch(url, {
191213
method: "POST",
@@ -247,6 +269,7 @@ export declare namespace prepare {
247269
currency?: string;
248270
maxSteps?: number;
249271
excludeChainIds?: string | string[];
272+
country?: string;
250273
/**
251274
* @hidden
252275
*/

0 commit comments

Comments
 (0)