React
Getting started
This package provides binding for omniston-sdk to the React ecosystem. Using this package, you can access all Omniston methods as hooks powered by TanStack react query (out-of-box loading states, retries, error handling, and match more)
You can find all supported methods in our docs or take a look onto our demo app that use NextJs and omniston-sdk-react
package
Installation
via NPM
via YARN
via PNPM
Wrap you app in Omniston provider
You can pass custom queryClient
if you want to apply shared behaviour to all of the queries
The provider takes the following parameters:
Name | Type | Description |
---|---|---|
|
| Optional. Provide this if you want to override the default API client. By default, this will be an |
|
| Omniston WebSocket API URL. |
Get list of supported assets
An AssetsResponse
has the following properties:
Name | Type | Description |
---|---|---|
|
| List of supported assets |
An AssetInfo
has the following properties:
Name | Type | Description |
---|---|---|
|
| Address of smart contract |
|
| Asset tags |
|
| Asset symbol |
|
| Displayable name |
|
| URL to asset image |
|
| Number of decimal places used to represent fractional amounts of an asset |
|
| Additional metadata, excluding above fields |
An Address
has the following properties:
Name | Type | Description |
---|---|---|
|
| Blockchain type (e.g. |
|
| Address of smart contract |
Send a quote request
Send a request for quote to swap an asset to another asset.
A QuoteRequest
has the following properties:
Name | Type | Description |
---|---|---|
|
| Supported methods of swap settlement |
|
| Blockchain-specific address of ask asset |
|
| Blockchain-specific address of offer asset |
|
| Either the amount of offer asset or ask asset |
|
| The amount of offer asset the trader wants to pay, including all fees, in base asset units |
|
| The amount of ask asset the trader wants to get after all fees, in base asset units |
|
| The address of referrer that will receive the fees |
|
| The amount of fees required by the referrer in basis points (1/10000 or 0.01%) |
The server returns Observable<Quote | null>
, which is a stream of quotes. Learn more about Observable types in the official RxJS documentation.
A Quote
has the following properties:
Name | Type | Description |
---|---|---|
|
| ID of the quote generated by the platform |
|
| ID of the resolver |
|
| Name of the resolver |
|
| Blockchain-specific address of offer asset |
|
| Blockchain-specific address of ask asset |
|
| The amount of offer asset the trader must pay, including all fees |
|
| The amount of ask asset the trader will get after all fees |
|
| The address of referrer that will receive the fees |
|
| The amount of fees that the referrer will get (in units of |
|
| The amount of fees charged by the protocol (in units of |
|
| The timestamp (UTC seconds) of Quote sent by resolver |
|
| Max timestamp (UTC seconds) of start of the trade |
|
| Various parameters specific to the settlement method. See the source code for more details. |
Build a transaction
Now that we have a quote, we should request a server to build a transaction to initiate the trade that the user can verify and sign.
The buildTransfer
method takes a TransactionRequest
object as a parameter, having the following properties:
Name | Type | Description |
---|---|---|
|
| The valid quote received from |
|
| The address on |
|
| The address on |
|
| Max price slippage in basis points (1/10000 or 0.01%) |
Sign the transaction
You can found the instruction on how to send transaction using the @tonconnect/ui-react
package here.
Listen for trade status updates
After the user has signed and initiated the transaction, we can track the trade status.
The trackTrade
method has the following parameters:
Name | Type | Description |
---|---|---|
|
| ID of the quote received from |
|
| The address of trader's wallet that initiated transaction |
It returns Observable<TrackTradeStatus>
. For the different trade status values, see the source code. We are interested in the trade result enum which can be read from status.tradeSettled?.result?
field. The enum has the following values:
Name | Description |
---|---|
| The trade has been completed and fully filled. |
| The trade has been partially filled. Something went wrong. |
| The trade has been aborted. |
| |
|
Last updated