Common SDK Error Messages
If you're encountering issues with our SDK, this guide will help you understand some of our common SDK error messages.
Chain is not available
This error occurs when the connect()
function in the SDK throws an error:
Error Message
If you encounter a "Chain is not available" error, it could mean one of three reasons:
- The value of the supplied
chainSlug
parameter in thewallet.connect()
function is incorrect:
-
The value of the supplied
chainSlug
parameter in thewallet.connect()
function is correct but however, the chain has been disabled by Swing. -
The value of the supplied
chainSlug
parameter in thewallet.connect()
function is correct but has been disabled in your projects rules configurations.
Chain Is Not Supported
This error occurs when the getQuote()
function in the SDK throws an error. It indicates that the supplied fromChain
or toChain
slug value is not available on Swing:
Error Message
If you encounter a "Chain Is Not Supported" error, it could mean one of three reasons:
- The value of the supplied
fromChain
ortoChain
parameter in the quotetransferParams
object is incorrect:
-
The value of the supplied
fromChain
ortoChain
parameter in the quotetransferParams
object is correct but however, the chain has been disabled by Swing. -
The value of the supplied
fromChain
ortoChain
parameter in the quotetransferParams
object is correct but has been disabled in your projects rules configurations.
Token Is Not Supported
This error occurs when the getQuote()
function in the SDK throws an error. It indicates that the supplied token slug on the connected chain is not available on Swing:
Error Message
If you encounter a "Token Is Not Supported" error, it could mean one of three reasons:
- The supplied
fromToken
ortoToken
parameter in the quotetransferParams
object is incorrect:
-
The value of the supplied
fromToken
ortoToken
parameter in the quotetransferParams
object is correct but however, the token has been disabled by Swing -
The value of the supplied
fromToken
ortoToken
parameter in the quotetransferParams
object is correct but has been disabled in your projects rules configurations
Transfer Failed
This error occurs when the transfer()
function in the SDK throws an error:
It is important to note that sending a transaction to the blockchain is an asynchronous process. Therefore, you can only receive real-time updates on the status of your transaction by listening to the SDK's internal event listener:
When you execute the transfer()
function, your pending transactions goes through four (4) phases/steps, each step has a corresponding transaction status attached to it:
Step | Description |
---|---|
Allowance | Swing is instructed on the amount of allocated tokens to be swapped or bridged. |
Approval | The user must sign the approval transaction using their wallet for the process to continue. |
Send | Swing will proceed to bridge or swap the approved tokens. |
Bridge | The assets have been received by Swing and will be swapped or bridged to the destination chain. |
The Allowance and Approval steps are optional and only required when the source token (
fromToken
) is an ERC20 token.
The event listener's callback function receives two arguments:
- transferStepStatus: Returns an object that provides the current step of a transaction as well as it's corresponding status:
- transferResults: Returns an object that provides the statuses of all the steps involved in a transaction. This helps to monitor the progress and outcome of each step, allowing for detailed tracking and troubleshooting:
Transaction Statuses
Below is a list of transaction statuses that are returned by the status
property in both the transferStepStatus
and the transferResults
objects:
Status | Description |
---|---|
PENDING | The transaction at a particular step has started and is pending. |
SUCCESS | The transaction at a particular step has been completed. |
FAILED | The transaction at a particular step has failed. |
Transaction Step Statuses
Below is a list of transaction statuses that are returned by the status
property and is exclusive to the transferStepStatus
objects:
Status | Description |
---|---|
ACTION_REQUIRED | User action is required such as interacting with metamask |
CHAIN_SWITCH_REQUIRED | Wallet needs to switch chains before continuing |
WALLET_CONNECTION_REQUIRED | Wallet with address needs to be connected |
CONFIRMING | Waiting for transaction confirmation |
BRIDGING | Waiting for bridge contract transaction to complete |
It's important to note that these statuses apply to the
status
property for every step (i.e., allowance, approval, send, bridge).
Handling failed transactions
The transferResults object contains the overall status of a transaction. Therefore, you can use the status property on the transferResults to determine the transaction's status, regardless of its current step.
To ensure that you're displaying a human-readable error, we suggest using the status property on the transferResults
object to determine the finality of a transaction, as its status will remain PENDING until the transaction either fails or completes, regardless of the transaction's current step:
A transaction can fail due to handful of reasons. A typical error message from the SDK would look something like this:
From the error object above, it is clear that the transaction failed at the send step. The error message, "execution reverted: ERC20: transfer amount exceeds balance", suggests that the wallet involved in this transaction did not have enough tokens to complete the transaction..
Here are the most common reasons why a transaction would fail and what to look out for:
Error | Description | |
---|---|---|
execution reverted: ERC20: transfer amount exceeds balance | Wallet has insufficient ERC20 tokens to fund the transaction | |
Insufficient Funds For Intrinsic Transaction Cost | Wallet has insufficient native tokens to fund the transaction | |
CHAIN_SWITCH_REQUIRED | Wallet needs to switch chains before continuing | |
WALLET_CONNECTION_REQUIRED | Wallet with address needs to be connected |
Handling CHAIN_SWITCH_REQUIRED Exception
CHAIN_SWITCH_REQUIRED
is an instruction from the SwingSDK to our dApp, requiring us to switch our wallet's network to continue the transaction on the correct chain.
As part of this instruction, the SDK will also return the chainId
to which you must switch for the transaction to proceed. It is important to note that failing to switch to the correct chainId
will result in a CHAIN_SWITCH_REQUIRED
exception.
A CHAIN_SWITCH_REQUIRED
exception occurs when the chain to which a wallet is connected differs from the source chain (chainSlug
) that the SDK is connected to.
To fix this issue, two steps are required:
- First, switch connected wallet's networks to the value provided in
transferStepStatus.chain.id
:
- Next, Sync the SDK with the wallet's provider by calling the
wallet.connect()
function again on the SDK:
For instance, if you are connected to the Arbitrum network and are bridging your assets from Polygon (MATIC) on the source chain to Ethereum (USDC) on the destination chain, the SDK will return a CHAIN_SWITCH_REQUIRED
status. This indicates that you must programmatically switch your wallet's connected chain from Arbitrum to Polygon.
Here's an example on how you can do this using Web3React
:
From our transferParams
object, we're transacting from the Polygon network. If we're connected to any chain other than Polygon, the SDK will instruct us to switch chains.
Using Web3React
, we can switch chains by calling the connector.activate()
function, which is available through the useWeb3React()
hook, and then passing transferStepStatus.chain.id
as the chainId:
Our useEffect
hook listens for changes to the chainId
property. By calling connector.activate({ chainId: transferStepStatus.chain.id });
, our hook will be triggered, which will then reconnect the SDK to the correct chainId: