Approving Non-Native Tokens
This section is only applicable to transfers of non-native tokens on EVM Compactible Chains. Non-native tokens include governance tokens, wrapped tokens, stablecoins, and oracle tokens.
If you are executing a transfer with a non-native token, our Swing Contract requires the right allowance limit to spend/withdraw funds (denominated in non-native tokens) from the designated wallet address.
Depending on the non-native token amount you are looking to transfer, you want to call our /approve
endpoint with a limit greater than or equal to the amount you are transferring.
You can use the /allowance
endpoint to determine if you have already approved a sufficient limit to allow your non-native token transfer. Importantly, the allowance limit is specific to the token, chain and bridge. So you must approve an allowance limit every time for every unique transfer combination of token, chain or bridge.
Checking Allowance Limit
We can query our /allowance
endpoint in the following manner to get the allowance limit.
The full API reference for our /allowance endpoint can be found in the API reference section.
Making a Request
URL: https://swap.prod.swing.xyz/v0/transfer/allowance
Query Parameters:
Property | Example | Description |
---|---|---|
fromChain | ethereum | Source Chain slug |
fromAddress | 0x018c15DA1239B84b08283799B89045CD476BBbBb | Sender's wallet address |
tokenAddress | 0x0000000000000000000000000000000000000000 | Source Token Address |
tokenSymbol | ETH | Source Token slug |
toTokenAddress | 0x0000000000000000000000000000000000000000 | Destination Token Address. |
toTokenSymbol | USDC | Destination Token slug |
toChain | polygon | Destination Chain slug |
projectId | replug | Your project's ID |
bridge | openocean | selected bridge/route to execute transaction |
contractCall | false | Indicate contract call allowance limit |
This will always only return the allowance limit for that specific token, on the specific chain for that specific bridge:
Requesting Approval Calldata
If you need to approve a higher allowance limit, you can query our /approve
endpoint in the following manner
The full API reference for our /approve endpoint can be found in the API reference section.
Making a Request
URL: https://swap.prod.swing.xyz/v0/transfer/approve
Query Parameters:
Property | Example | Description |
---|---|---|
tokenAmount | 1000000000000000000 | Amount of the source token being sent (in wei for ETH). |
fromChain | ethereum | Source Chain slug |
fromAddress | 0x018c15DA1239B84b08283799B89045CD476BBbBb | Sender's wallet address |
fromTokenAddress | 0x0000000000000000000000000000000000000000 | Source Token Address |
tokenSymbol | ETH | Source Token slug |
toTokenAddress | 0x0000000000000000000000000000000000000000 | Destination Token Address. |
toTokenSymbol | USDC | Destination Token slug |
toChain | polygon | Destination Chain slug |
projectId | replug | Your project's ID |
bridge | openocean | selected bridge/route to execute transaction |
contractCall | false | Indicate contract call allowance limit |
It is important to note that executing an approval is optional and only required for Non-Native swap/bridge transactions.
An approval is required only if the allowance limit from the /allowance
enpdoint is less than or equal to the tokenAmount
supplied in the quote.
Since approve is a contract-level function, Swing only returns the necessary call-data that will need to be signed and executed by the local wallet (ie. Metamask, Coinbase Wallet, WalletConnect, etc).
It's important to note that the token approval process is only available for EVM Compatible chains. Meaning that the source chain you supply to the /approve
must be an EVM chain. To determine if a chain is EVM-compatible, check its type
property, which is returned when you call the /chains
endpoint.
Skipping this check will result in the /approval
endpoint returning an error to the user:
Requesting Approval Calldata for Contract Calls
If you need to approve a higher allowance limit for a Contract call transaction, you can set the contractCall
API parameter to true
Making a Request
URL: https://swap.prod.swing.xyz/v0/transfer/approve
Query Parameters:
Property | Example | Description |
---|---|---|
contractCall | false | Indicate contract call operation |
Since approve is a contract-level function, Swing only returns the necessary call-data that will need to be signed and executed by the local wallet (ie. Metamask, Coinbase Wallet, WalletConnect, etc).
It's important to note that the token approval process is only available for EVM Compatible chains. Meaning that the source chain you supply to the /approve
must be an EVM chain. To determine if a chain is EVM-compatible, check its type
property, which is returned when you call the /chains
endpoint.
Skipping this check will result in the /approval
endpoint returning an error to the user: