-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PARTNER-63] Add documentation for integrating with the Anchor with c…
…ode examples (#164) * Add basic docs * SEP-10 docs * Add server side implementation * Small refactoring * SEP-24 skeleton * Interactive documentation * Small change * Add watcher and get transaction docs * Finish documentation * Prettifying * Small additions * Move docs * grammatical fixes * grammatical fixes * grammatical fixes * grammatical fixes * grammatical fixes * formatting --------- Co-authored-by: Bri <[email protected]>
- Loading branch information
1 parent
19b1dce
commit 0e5896a
Showing
9 changed files
with
1,112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"position": 45, | ||
"label": "Building a Wallet", | ||
"link": { | ||
"type": "generated-index" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
--- | ||
title: Getting Started | ||
sidebar_position: 20 | ||
--- | ||
|
||
import { CodeExample } from "@site/src/components/CodeExample"; | ||
|
||
In this guide, we will use the Kotlin Wallet SDK to integrate with the Stellar blockchain and connect to anchors. | ||
|
||
## Installation | ||
|
||
First, you need to add the SDK dependency to your project. | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
// gradle.kts | ||
implementation("org.stellar:wallet-sdk:[version]") | ||
``` | ||
|
||
</CodeExample> | ||
|
||
You can get the latest available version on the [project GitHub page](https://github.com/stellar/kotlin-wallet-sdk). | ||
|
||
## Working with the SDK | ||
|
||
Let's start with the main class that provides all SDK functionality. It's advised to have a singleton wallet object shared across the application. Creating a wallet with a default configuration connected to Stellar's Testnet is simple: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val wallet = Wallet(StellarConfiguration.Testnet) | ||
``` | ||
|
||
</CodeExample> | ||
|
||
The wallet instance can be further configured. For example, to connect to the public network: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val walletMainnet = Wallet(StellarConfiguration(Network.PUBLIC, "https://horizon.stellar.org")) | ||
``` | ||
|
||
</CodeExample> | ||
|
||
There is one more available configuration for a wallet that allows it to configure internal logic of the SDK. For example, to test with local servers on an HTTP protocol, HTTP can be manually enabled. | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val walletCustom = Wallet( | ||
StellarConfiguration.Testnet, | ||
ApplicationConfiguration { defaultRequest { url { protocol = URLProtocol.HTTP } } } | ||
) | ||
``` | ||
|
||
</CodeExample> | ||
|
||
### Configuring the Client | ||
|
||
The wallet SDK uses the [ktor client](https://ktor.io/docs/getting-started-ktor-client.html) for all network requests (excluding Horizon, where the Stellar SDK's HTTP client is used). Currently, the okhttp engine is configured to be used with the client. You can read more about how to configure the ktor client [here](https://ktor.io/docs/create-client.html#configure-client). | ||
|
||
For example, the client can be globally configured: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val walletCustomClient = | ||
Wallet( | ||
StellarConfiguration.Testnet, | ||
ApplicationConfiguration( | ||
defaultClientConfig = { | ||
engine { this.config { this.connectTimeout(Duration.ofSeconds(10)) } } | ||
install(HttpRequestRetry) { | ||
retryOnServerErrors(maxRetries = 5) | ||
exponentialDelay() | ||
} | ||
} | ||
) | ||
) | ||
``` | ||
|
||
</CodeExample> | ||
|
||
This code will set the connect timeout to ten seconds via the [okhttp configuration](https://ktor.io/docs/http-client-engines.html#okhttp) and also installs the [retry plugin](https://ktor.io/docs/client-retry.html). You can also specify client configuration for specific wallet SDK classes. | ||
|
||
For example, to change connect timeout when connecting to some anchor server: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val anchorCustomClient = | ||
walletCustomClient.anchor("example.com") { | ||
engine { this.config { this.connectTimeout(Duration.ofSeconds(30)) } } | ||
} | ||
``` | ||
|
||
</CodeExample> | ||
|
||
### Closing Resources | ||
|
||
After the wallet class is no longer used, it's necessary to close all clients used by it. While in some applications it may not be required (e.g. the wallet lives for the whole lifetime of the application), in other cases it can be required. If your wallet class is short-lived, it's recommended to close client resources using a close function: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
fun closeWallet() { | ||
wallet.close() | ||
} | ||
``` | ||
|
||
</CodeExample> | ||
|
||
## Stellar Basics | ||
|
||
The wallet SDK provides some extra functionality on top of the existing [Horizon SDK]. For interaction with the Stellar network, the wallet SDK covers only the basics used in a typical wallet flow. For more advanced use cases, the underlying [Horizon SDK] should be used instead. | ||
|
||
To interact with the Horizon instance configured in the previous steps, simply do: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val stellar = wallet.stellar() | ||
``` | ||
|
||
</CodeExample> | ||
|
||
This example will create a Stellar class that manages the connection to Horizon service. | ||
|
||
:::note | ||
|
||
Default configuration connects to the public Stellar Horizon instance. You can change this behavior as described [above](#working-with-the-sdk). | ||
|
||
::: | ||
|
||
You can read more about working with the Stellar network in the [respective section](./stellar.mdx). | ||
|
||
## Anchor Basics | ||
|
||
Primary use of the SDK is to provide an easy way to connect to anchors via sets of protocols known as SEPs. Let's look into connecting to the Stellar test anchor: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val anchor = wallet.anchor("https://testanchor.stellar.org") | ||
``` | ||
|
||
</CodeExample> | ||
|
||
And the most basic interaction of fetching a [SEP-1]: Stellar Info File: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
suspend fun anchorToml(): TomlInfo { | ||
return anchor.getInfo() | ||
} | ||
``` | ||
|
||
</CodeExample> | ||
|
||
The anchor class also supports [SEP-10]: Stellar Authentication and [SEP-24]: Hosted Deposit and Withdrawal features. | ||
|
||
[sep-1]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md | ||
[sep-10]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md | ||
[sep-12]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md | ||
[sep-24]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md | ||
[sep-10]: ./sep10.mdx | ||
[sep-24]: ./sep24.mdx | ||
[horizon sdk]: /docs/tools-and-sdks#sdk-library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
title: Overview | ||
sidebar_position: 10 | ||
--- | ||
|
||
import { CodeExample } from "@site/src/components/CodeExample"; | ||
|
||
## What is a Wallet? | ||
|
||
A wallet is an application that allows users to hold assets, such as Stellar's native asset (XLM), stablecoins (USDC), or any other asset issued on chain. Wallets can also help users exchange their assets, sometimes using entities called anchors. | ||
|
||
## Custodial versus Non-Custodial Wallets | ||
|
||
Some applications, such as centralized exchanges, are custodial, meaning the application has access to the private keys of the accounts holding its users’ funds on Stellar. Typically, custodial applications pool user funds into a smaller set of managed Stellar accounts, called pooled, shared, or omnibus accounts. | ||
|
||
Other applications are non-custodial, meaning the application does not have access to the private keys of the accounts holding its users' funds on Stellar. Typically, non-custodial applications create or import a pre-existing Stellar account for each user. | ||
|
||
These two approaches require minor but concrete differences in how applications integrate with an anchor. The sub-sections below will describe these differences, but the rest of this tutorial will assume the application is custodial. | ||
|
||
## What is an Anchor? | ||
|
||
An anchor is a Stellar-specific term for the on and off-ramps that connect the Stellar network to traditional financial rails, such as financial institutions or fintech companies. Anchors accept deposits of fiat currencies (such as the US dollar, Argentine peso, or Nigerian naira) via existing rails (such as bank deposits or cash-in points), then sends the user the equivalent digital tokens on the Stellar network. The equivalent digital tokens can either represent that same fiat currency or another digital token altogether. Alternatively, anchors allow token holders to redeem their tokens for the real-world assets they represent. | ||
|
||
Stellar has anchor services operating worldwide. View the [Anchor Directory](https://resources.stellar.org/anchors?) for more information on existing Stellar anchors. | ||
|
||
This documentation will instruct you on how to connect to the anchor as the wallet. | ||
|
||
## Stellar Ecosystem Proposals (SEPs) and Interoperability | ||
|
||
Stellar is an open-source network that is designed to interoperate with traditional financial institutions, various types of assets, and other networks. Network participants implement Stellar Ecosystem Proposals (SEPs) to ensure they can interoperate with other products and services on the network. SEPs are publicly created, open-source documents that live in a [GitHub repository](https://github.com/stellar/stellar-protocol/tree/master/ecosystem#stellar-ecosystem-proposals-seps) and they define how asset issuers, applications, exchanges, and other service providers should interact and interoperate. | ||
|
||
Read more about SEPs in the [SEPs section](https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-ecosystem-proposals). | ||
|
||
As a wallet, the most important SEPs are [SEP-24]: Hosted Deposit and Withdrawal, and [SEP-31]: Cross Border Payments API. You’ll also work with [SEP-10]: Stellar Authentication, [SEP-12]: KYC API, and [SEP-38]: Anchor RFQ API. | ||
|
||
[sep-1]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md | ||
[sep-9]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0009.md | ||
[sep-10]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md | ||
[sep-12]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md | ||
[sep-24]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md | ||
[sep-31]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0031.md | ||
[sep-38]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0038.md |
Oops, something went wrong.