Comment on page
This guide will walk you through how to perform swaps with Portal's Android SDK.
PortalSwapsclass allows you to easily extend your existing
Portalinstance with swaps functionality.
val swaps = Swaps("SWAPS-API-KEY", portal)
getSources()function returns a
Map<String, String>containing valid, swappable token sources that can be used with your Portal MPC Wallet. The existing
Portalinstance that was provided at initialization is used to scope the request to the current chain.
In order to retrieve this list, you can use the following code.
val sources = swaps.getSources()
The Map returned by the
getSources()function is a set of key/value pairs where the key is the name of the token and the value is the token address for that token.
getQuote()function returns a
Quoteobject for a given set of arguments.
The minimum requirements for a valid set of
Quotearguments are a
sellToken, and either a
An example of a valid
QuoteArgsobject would look something like this.
val quoteArgs = QuoteArgs(
Once you have a valid
QuoteArgsobject, you can call the
val quote = swaps.getQuote(quoteArgs)
Quoteobject includes two properties:
allowanceTargetThe address requiring allowances to complete the Swap
costThe total cost (gas fees) of the swap transaction
transactionThe transaction to perform the swap
If you're selling ERC20 tokens, you'll need to utilize the
allowanceTargetto give the associated contract permissions to access a given amount of the token you're selling. This requires a token allowance of at least what you're selling. If you're selling
ETH, this step is not necessary.
When you're ready to execute a swap, you can use the
Provideron your existing
Portalinstance to sign the transaction and make a request to chain.