This guide is available on four different programming languages: Typescript, Kotlin, Flutter (Dart) and Swift. You can change the shown version on each page via the buttons above.
Creating SEP-38 Object
Let’s start with creating a sep38 object, which we’ll use for all SEP-38 interactions. Authentication is optional for these requests, and depends on the anchor implementation. For our example we will include it. Authentication is done using Sep-10, and we add the authentication token to the sep38 object.- TypeScript
- Flutter
- Swift
Get Anchor Information
First, let’s get information about the anchor’s support for SEP-38. The response gives what stellar on-chain assets and off-chain assets are available for trading.- TypeScript
- Flutter
- Swift
Asset Identification Format
Before calling other endpoints we should understand the scheme used to identify assets in this protocol. The following format is used:stellar for Stellar assets, and iso4217 for fiat currencies.
For example to identify USDC on Stellar we would use:
Get Prices
Now let’s get indicative prices from the anchor in exchange for a given asset. This is an indicative price. The actual price will be calculated at conversion time once the Anchor receives the funds from a user. In our example we’re getting prices for selling 5 fiat USD.- TypeScript
- Flutter
- Swift
Get Price
Next, let’s get an indicative price for a certain pair. Once again this is an indicative value. The actual price will be calculated at conversion time once the Anchor receives the funds from a User. Either asellAmount or buyAmount value must be given, but not both. And context refers to what Stellar SEP context this will be used for (ie. sep6, sep24, or sep31).
- TypeScript
- Flutter
- Swift
Post Quote
Now let’s get a firm quote from the anchor. As opposed to the earlier endpoints, this quote is stored by the anchor for a certain period of time. We will show how we can grab the quote again later. The request body is similar to the.price() call we made earlier.
- TypeScript
- Flutter
- Swift
id that we can use to identify the quote. The expires_at field tells us how long the anchor will wait to receive funds for this quote.
An example response looks like this:
Get Quote
Now let’s get the previously requested quote. To do that we use theid from the .requestQuote() response.
- TypeScript
- Flutter
- Swift
.requestQuote() we made earlier.