Transactions
In the Basic SDK, you could get the transaction via swap endpoint. Please check this link for more information on this:
After that user signed a transaction on his/her wallet you should call this endpoint periodically to see what's the status of that transaction.
Typescript
cURL
const transaction = await rangoClient.status({
requestId: swapResponse.requestId,
txId: 'TX HASH RETURENED BY WALLET',
})
curl 'https://api.rango.exchange/basic/status?apiKey=YOUR_API_KEY' \
-H 'content-type: application/json;charset=UTF-8' \
-H 'x-rango-id: USER_RANDOM_UUID' \
-H 'origin: https://app.rango.exchange' \
--data-raw '{"txId":"TX HASH RETUREN BY WALLET","requestId":"BEST ROUTE REQUEST ID"}' \
--compressed
This endpoint is not suitable for checking approval and it is only for the original transaction.
Param | Description |
---|---|
requestId * | The unique ID which is generated in the swap endpoint. |
txId * | Tx hash that wallet returned, e.g. 0xa1a37ce2063c4764da27d990a22a0c89ed8... |
Field | Description |
---|---|
status | Status of the transaction, while the status is running or null , the client should retry until it turns into success orfailed . |
error | A message in case of failure, that could be shown to the user. |
output | The output asset and amount, could be different from the destination asset in case of failures and refunds. These are different output types possible:
'REVERTED_TO_INPUT' | 'MIDDLE_ASSET_IN_SRC' | 'MIDDLE_ASSET_IN_DEST' | 'DESIRED_OUTPUT' |
explorerUrl | List of explorer URLs for the transactions of this swap. |
bridgeData | Status of bridge |
When
swap
returns a not null value for approveData
and approveTo
, you need to use these values to show approve transaction to the user and call isApproved
periodically to see if the approval tx is completed. After a successful check, you should create the main transaction using txData
, txTo
and value.Typescript
cURL
const transaction = await rangoClient.isApproved(
requestId = bestRoute.requestId,
txId = 'APPROVE TX HASH RETURENED BY WALLET
)
curl 'https://api.rango.exchange/basic/is-approved?apiKey=YOUR_API_KEY&requestId=REQUEST_ID&txId=TX_HASH' \
-H 'x-rango-id: USER_RANDOM_UUID' \
-H 'origin: https://app.rango.exchange'
Param | Description |
---|---|
requestId * | The unique ID which is generated in the best route endpoint. |
txId * | Tx hash that wallet returned for approve tx, e.g. 0xa1a37ce2063c4764da27d990a22a0c89ed8... |
Field | Description |
---|---|
isApproved | A flag that indicates that the approval tx is done or not. |
Use it when the user rejects the transaction in the wallet or the wallet fails to handle the transaction. Calling this endpoint is not required, but is useful for reporting and we recommend calling it.
Typescript
cURL
const transaction = await rangoClient.reportFailure({
requestId: swapResponse.requestId,
eventType: 'TX_FAIL',
data: {
extraMessage: "Error sending transaction",
extraMessageDetail: "User Denied",
eventType: "smart_contract_call_failed"
}
})
curl 'https://api.rango.exchange/basic/report-tx?apiKey=YOUR_API_KEY' \
-H 'content-type: application/json;charset=UTF-8' \
-H 'origin: https://app.rango.exchange' \
--data-raw '{"requestId":"BEST ROUTE REQUEST ID","eventType":"TX_FAIL","data":{"extraMessage":"Error sending transaction","extraMessageDetail":"User Denied","eventType":"smart_contract_call_failed"}}' \
--compressed
It's an optional action and does not affect the flow of swap, but it can help us improve our API if the data is informative enough
Param | Description |
---|---|
requestId * | The unique ID which is generated in the best route endpoint. |
eventType * | TX_FAIL |
data * | Failure reason |
Last modified 7mo ago