Checking a Transaction's Status
To fetch the execution status of a transfer, the /status endpoint can be queried. View the full API reference for the
/status
endpoint here.
The next step in our transaction flow is a status check. You can check the status of a transaction by querying the /status
endpoint.
Checking a transaction's status is important because it has two (2) essential functions:
- It let's you know the current state of your transaction.
- Most importantly, it also reports the
txHash
of your transaction to Swing, which enables Swing to track your transaction on the blockchain.
List of Transaction Statuses
Below is a list of statuses that are returned from the transaction status check endpoint.
Name | Description |
---|---|
Not Sent | The transaction has been received by Swing but has not yet been authorized/signed by a user's wallet |
Submitted | The transaction has been signed by a user and has been submitted to the blockchain |
Pending Source Chain | The transaction has been submitted to the source chain's bridge awaiting confirmation |
Pending Destination Chain | The transaction is awaiting confirmation on the destination chain |
Completed | The transaction has been successfully completed and funds have been received on the destination chain |
Refund Required | The tokens are stuck on the bridge and requires a refund |
Refunded | The transaction has been refunded to the user |
Failed Source Chain | The transaction failed on the source chain |
Failed Destination Chain | The transaction failed on the destination chain |
Fallback | The token swap fails on the destination chain and instead of getting the toToken assets, the user gets the bridge token |
Claim Required | The transaction is still in-progress, but requires a claim step to complete the transfer on the destination chain |
It's important to note that if the /status
endpoint is not queried at least once after a transaction is sent, the transaction will not appear in the Transactions
section of your platform's dashboard. Once the transaction's status has been queried, it will be displayed on your dashboard:
Making a Request
GET: https://swap.prod.swing.xyz/v0/transfer/status
Query Parameters:
Key | Example | Description |
---|---|---|
id | 239750 | Transaction ID from /send response |
txHash | 0x3b2a04e2d16489bcbbb10960a248..... | The transaction hash identifier. |
projectId | replug | Your project's ID |
Sample Request
Response
Polling Transaction Status
For the sake of user experience, while a live transaction is processing, it’s best to periodically poll the transaction status endpoint to check if the transaction is complete. This will keep your users informed about the status of their transactions in real time.
Let's define a function for checking a transaction's status:
Polling the transaction status endpoint means that we will be periodically querying the /status
endpoint until the status property in the response is no longer one of the following:
- Submitted
- Not Sent
- Pending Source Chain
- Pending Destination Chain
Once the transaction status does not match any of the following, it indicates that the /send
endpoint has returned a status message specifying whether the transaction has failed or completed.
Next, We will use setTimeout()
to execute our getStatus()
function every 5000 milliseconds recursively until the conditions stated above are met.
Next, we will call our pollTransactionStatus()
function right after executing our callData
: