-
Notifications
You must be signed in to change notification settings - Fork 30
Add: Transak Fiat Module Docs #209
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
Draft
agtransak
wants to merge
2
commits into
tetherto:main
Choose a base branch
from
agtransak:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
377 changes: 377 additions & 0 deletions
377
content/docs/sdk/fiat-modules/fiat-transak/api-reference.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,377 @@ | ||
| --- | ||
| title: Fiat Transak API Reference | ||
| description: API Reference for the @tetherto/wdk-protocol-fiat-transak module | ||
| docType: reference | ||
| schemaType: APIReference | ||
| icon: Code | ||
| --- | ||
|
|
||
| # API Reference | ||
|
|
||
| Complete API documentation for the `@tetherto/wdk-protocol-fiat-transak` module. | ||
|
|
||
| ## Constructor | ||
|
|
||
| ### `new TransakProtocol(account, config)` | ||
|
|
||
| Creates a new TransakProtocol instance. | ||
|
|
||
| **Parameters:** | ||
|
|
||
| | Name | Type | Description | | ||
| |------|------|-------------| | ||
| | `account` | `IWalletAccount` \| `IWalletAccountReadOnly` \| `undefined` | Wallet account for transactions | | ||
| | `config` | `TransakProtocolConfig` | Configuration object | | ||
|
|
||
| **Config Options:** | ||
|
|
||
| | Name | Type | Required | Default | Description | | ||
| |------|------|----------|---------|-------------| | ||
| | `apiKey` | string | Yes | - | Your Transak partner API key | | ||
| | `widgetUrl` | function | For `buy`/`sell` | - | Callback `(widgetParams) => Promise<string>` that returns a session-based widget URL. `buy`/`sell` throw without it. | | ||
| | `getOrder` | function | For `getTransactionDetail` | - | Callback `(txId) => Promise<TransakOrder>` that fetches a Transak order. `getTransactionDetail` throws without it. | | ||
| | `cacheTime` | number | No | `600000` | Cache duration for supported currencies (ms) | | ||
| | `environment` | `'PRODUCTION' \| 'STAGING'` | No | `PRODUCTION` | Selects the Transak API host | | ||
|
|
||
| **Example:** | ||
|
|
||
| ```typescript | ||
| import TransakProtocol from '@tetherto/wdk-protocol-fiat-transak'; | ||
|
|
||
| const transak = new TransakProtocol(walletAccount, { | ||
| apiKey: 'YOUR_TRANSAK_PARTNER_KEY', | ||
| widgetUrl: async (widgetParams) => { /* call your backend */ }, | ||
| getOrder: async (txId) => { /* call your backend */ }, | ||
| environment: 'PRODUCTION', | ||
| }); | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Methods | ||
|
|
||
| ### `buy(options)` | ||
|
|
||
| Generates a Transak widget URL for purchasing cryptocurrency via the configured `widgetUrl` callback. | ||
|
|
||
| **Parameters:** | ||
|
|
||
| | Name | Type | Required | Description | | ||
| |------|------|----------|-------------| | ||
| | `options.cryptoAsset` | string | Yes | Crypto asset code, upper-case (e.g. `'ETH'`) | | ||
| | `options.fiatCurrency` | string | Yes | Fiat currency code, upper-case (e.g. `'EUR'`) | | ||
| | `options.cryptoAmount` | number \| bigint | No* | Amount in crypto base units (e.g. wei) | | ||
| | `options.fiatAmount` | number \| bigint | No* | Amount in fiat base units (e.g. cents) | | ||
| | `options.recipient` | string | No | Destination wallet address (falls back to the account address) | | ||
| | `options.config` | `TransakBuyParams` | No | Widget parameters, including `network` and the required `referrerDomain` | | ||
|
|
||
| *Either `cryptoAmount` or `fiatAmount` must be provided, but not both. | ||
|
|
||
| **Returns:** `Promise<{ buyUrl: string }>` | ||
|
|
||
| --- | ||
|
|
||
| ### `sell(options)` | ||
|
|
||
| Generates a Transak widget URL for selling cryptocurrency via the configured `widgetUrl` callback. | ||
|
|
||
| **Parameters:** | ||
|
|
||
| | Name | Type | Required | Description | | ||
| |------|------|----------|-------------| | ||
| | `options.cryptoAsset` | string | Yes | Crypto asset code, upper-case | | ||
| | `options.fiatCurrency` | string | Yes | Fiat currency code, upper-case | | ||
| | `options.cryptoAmount` | number \| bigint | No* | Amount in crypto base units | | ||
| | `options.fiatAmount` | number \| bigint | No* | Amount in fiat base units | | ||
| | `options.config` | `TransakSellParams` | No | Widget parameters, including `network` and the required `referrerDomain` | | ||
|
|
||
| *Either `cryptoAmount` or `fiatAmount` must be provided, but not both. | ||
|
|
||
| **Returns:** `Promise<{ sellUrl: string }>` | ||
|
|
||
| --- | ||
|
|
||
| ### `quoteBuy(options)` | ||
|
|
||
| Gets a price quote for a cryptocurrency purchase. | ||
|
|
||
| **Parameters:** | ||
|
|
||
| | Name | Type | Required | Description | | ||
| |------|------|----------|-------------| | ||
| | `options.cryptoAsset` | string | Yes | Crypto asset code, upper-case | | ||
| | `options.fiatCurrency` | string | Yes | Fiat currency code, upper-case | | ||
| | `options.cryptoAmount` | number \| bigint | No* | Amount in crypto base units | | ||
| | `options.fiatAmount` | number \| bigint | No* | Amount in fiat base units | | ||
| | `options.config` | `TransakQuoteBuyParams` | No | `paymentMethod` and `network` (resolved from the supported list when omitted) | | ||
|
|
||
| *Either `cryptoAmount` or `fiatAmount` must be provided, but not both. | ||
|
|
||
| **Returns:** `Promise<TransakBuyQuote>` | ||
|
|
||
| ```typescript | ||
| { | ||
| cryptoAmount: bigint, // Crypto amount you'll receive, in base units | ||
| fiatAmount: bigint, // Fiat amount to pay, in base units | ||
| fee: bigint, // Total fee, in fiat base units | ||
| rate: string, // Exchange rate, as a decimal string | ||
| metadata: TransakQuote // The full raw Transak quote | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### `quoteSell(options)` | ||
|
|
||
| Gets a price quote for selling cryptocurrency. | ||
|
|
||
| **Parameters:** | ||
|
|
||
| | Name | Type | Required | Description | | ||
| |------|------|----------|-------------| | ||
| | `options.cryptoAsset` | string | Yes | Crypto asset code, upper-case | | ||
| | `options.fiatCurrency` | string | Yes | Fiat currency code, upper-case | | ||
| | `options.cryptoAmount` | number \| bigint | Yes | Amount in crypto base units | | ||
| | `options.config` | `TransakQuoteSellParams` | No | `paymentMethod` and `network` (resolved from the supported list when omitted) | | ||
|
|
||
| **Returns:** `Promise<TransakSellQuote>` | ||
|
|
||
| ```typescript | ||
| { | ||
| cryptoAmount: bigint, // Crypto amount to sell, in base units | ||
| fiatAmount: bigint, // Fiat amount you'll receive, in base units | ||
| fee: bigint, // Total fee, in fiat base units | ||
| rate: string, // Exchange rate, as a decimal string | ||
| metadata: TransakQuote // The full raw Transak quote | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### `getSupportedCryptoAssets()` | ||
|
|
||
| Fetches the list of supported cryptocurrencies. Results are cached per `cacheTime`. | ||
|
|
||
| **Returns:** `Promise<TransakSupportedCryptoAsset[]>` | ||
|
|
||
| ```typescript | ||
| { | ||
| code: string, // Crypto asset code (e.g. 'ETH') | ||
| decimals: number, // On-chain base-unit decimal places | ||
| networkCode: string, // Network identifier (e.g. 'ethereum') | ||
| name: string, // Display name | ||
| metadata: TransakCryptoCurrencyDetails | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### `getSupportedFiatCurrencies()` | ||
|
|
||
| Fetches the list of supported fiat currencies. Results are cached per `cacheTime`. | ||
|
|
||
| **Returns:** `Promise<TransakSupportedFiatCurrency[]>` | ||
|
|
||
| ```typescript | ||
| { | ||
| code: string, // Fiat currency code (e.g. 'EUR') | ||
| decimals: number, // ISO 4217 decimal places for the smallest unit | ||
| name: string, // Display name | ||
| metadata: TransakFiatCurrencyDetails | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### `getSupportedCountries()` | ||
|
|
||
| Fetches the list of supported countries. | ||
|
|
||
| **Returns:** `Promise<TransakSupportedCountry[]>` | ||
|
|
||
| ```typescript | ||
| { | ||
| code: string, // ISO 3166-1 alpha-2 (or alpha-3 fallback) country code | ||
| isBuyAllowed: boolean, // Buy operations allowed | ||
| isSellAllowed: boolean, // Sell operations allowed | ||
| name: string, // Country name | ||
| metadata: TransakCountryDetail | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### `getTransactionDetail(txId)` | ||
|
|
||
| Retrieves the details of a specific order via the configured `getOrder` callback. | ||
|
|
||
| **Parameters:** | ||
|
|
||
| | Name | Type | Required | Description | | ||
| |------|------|----------|-------------| | ||
| | `txId` | string | Yes | The Transak order id | | ||
|
|
||
| **Returns:** `Promise<TransakTransactionDetail>` | ||
|
|
||
| ```typescript | ||
| { | ||
| status: 'completed' | 'failed' | 'in_progress', | ||
| cryptoAsset: string, | ||
| fiatCurrency: string, | ||
| metadata: TransakOrder // The full raw Transak order | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Types | ||
|
|
||
| ### `TransakProtocolConfig` | ||
|
|
||
| ```typescript | ||
| interface TransakProtocolConfig { | ||
| apiKey: string; | ||
| widgetUrl?: (widgetParams: TransakWidgetParams) => Promise<string>; | ||
| getOrder?: (txId: string) => Promise<TransakOrder>; | ||
| cacheTime?: number; | ||
| environment?: 'PRODUCTION' | 'STAGING'; | ||
| } | ||
| ``` | ||
|
|
||
| ### `TransakWidgetParams` | ||
|
|
||
| The parameters your `widgetUrl` callback receives. Send this object as `widgetParams` to Transak's Create Widget URL API. | ||
|
|
||
| ```typescript | ||
| interface TransakWidgetParams { | ||
| apiKey: string; | ||
| productsAvailed: 'BUY' | 'SELL'; | ||
| cryptoCurrencyCode: string; | ||
| network: string; | ||
| fiatCurrency: string; | ||
| fiatAmount?: number; | ||
| cryptoAmount?: number; | ||
| walletAddress?: string; | ||
| } | ||
| ``` | ||
|
|
||
| ### `TransakBuyParams` | ||
|
|
||
| Widget configuration options for `buy()` operations. Refer [here](https://docs.transak.com/customization/query-parameters) for all supported Transak's query parameters. | ||
|
|
||
| ```typescript | ||
| interface TransakBuyParams { | ||
| // Shared UI options | ||
| themeColor?: string; | ||
| colorMode?: 'DARK' | 'LIGHT'; | ||
| redirectURL?: string; | ||
| referrerDomain?: string; // required by buy()/sell() | ||
| hideMenu?: string; | ||
|
|
||
| // Buy-specific options | ||
| defaultCryptoCurrency?: string; | ||
| walletAddress?: string; | ||
| walletAddressesData?: string; | ||
| disableWalletAddressForm?: boolean; | ||
| hideExchangeScreen?: boolean; | ||
| isFeeCalculationHidden?: boolean; | ||
| defaultPaymentMethod?: string; | ||
| paymentMethod?: string; | ||
| email?: string; | ||
| partnerOrderId?: string; | ||
| partnerCustomerId?: string; | ||
| network?: string; | ||
| } | ||
| ``` | ||
|
|
||
| ### `TransakSellParams` | ||
|
|
||
| Widget configuration options for `sell()` operations. Refer [here](https://docs.transak.com/customization/query-parameters) for all supported Transak's query parameters. | ||
|
|
||
| ```typescript | ||
| interface TransakSellParams { | ||
| // Shared UI options | ||
| themeColor?: string; | ||
| colorMode?: 'DARK' | 'LIGHT'; | ||
| redirectURL?: string; | ||
| referrerDomain?: string; // required by buy()/sell() | ||
| hideMenu?: string; | ||
|
|
||
| // Sell-specific options | ||
| defaultCryptoCurrency?: string; | ||
| walletAddress?: string; | ||
| walletAddressesData?: string; | ||
| disableWalletAddressForm?: boolean; | ||
| hideExchangeScreen?: boolean; | ||
| isFeeCalculationHidden?: boolean; | ||
| defaultPaymentMethod?: string; | ||
| paymentMethod?: string; | ||
| email?: string; | ||
| partnerOrderId?: string; | ||
| partnerCustomerId?: string; | ||
| network?: string; | ||
| } | ||
| ``` | ||
|
|
||
| ### `TransakQuoteBuyParams` | ||
|
|
||
| ```typescript | ||
| interface TransakQuoteBuyParams { | ||
| paymentMethod?: string; | ||
| network?: string; // resolved from the supported assets list when omitted | ||
| } | ||
| ``` | ||
|
|
||
| ### `TransakQuoteSellParams` | ||
|
|
||
| ```typescript | ||
| interface TransakQuoteSellParams { | ||
| paymentMethod?: string; | ||
| network?: string; // resolved from the supported assets list when omitted | ||
| } | ||
| ``` | ||
|
|
||
| ### `TransakOrder` | ||
|
|
||
| The raw order object returned by your `getOrder` callback, and exposed as `metadata` on `TransakTransactionDetail`: | ||
|
|
||
| ```typescript | ||
| interface TransakOrder { | ||
| id: string; | ||
| status: TransakOrderStatus; | ||
| cryptoCurrency: string; | ||
| fiatCurrency: string; | ||
| fiatAmount: number; | ||
| cryptoAmount?: number; | ||
| isBuyOrSell: 'BUY' | 'SELL'; | ||
| network: string; | ||
| walletAddress?: string; | ||
| transactionHash?: string; | ||
| amountPaid?: number; | ||
| createdAt?: string; // ISO 8601 | ||
| completedAt?: string; // ISO 8601 | ||
| } | ||
| ``` | ||
|
|
||
| ### `TransakOrderStatus` | ||
|
|
||
| ```typescript | ||
| type TransakOrderStatus = | ||
| | 'AWAITING_PAYMENT_FROM_USER' | ||
| | 'PAYMENT_DONE_MARKED_BY_USER' | ||
| | 'PROCESSING' | ||
| | 'PENDING_DELIVERY_FROM_TRANSAK' | ||
| | 'ON_HOLD_PENDING_DELIVERY_FROM_TRANSAK' | ||
| | 'COMPLETED' | ||
| | 'CANCELLED' | ||
| | 'FAILED' | ||
| | 'REFUNDED' | ||
| | 'EXPIRED'; | ||
| ``` | ||
|
|
||
| `getTransactionDetail` normalises these into `'completed'`, `'failed'`, or `'in_progress'` | ||
|
|
||
| ## Next Steps | ||
|
|
||
| - [Configuration](/sdk/fiat-modules/fiat-transak/configuration) - Setup and configuration options | ||
| - [Usage Guide](/sdk/fiat-modules/fiat-transak/usage) - Common usage patterns |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this source link need to point to
Transak/wdk-protocol-fiat-transak? The currenttetherto/wdk-protocol-fiat-transakURL returns 404, while the package manifest names the Transak repository.