Step 5: Watch a transaction 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.
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
: