-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PARTNER-63] Add documentation for integrating with the Anchor with code examples #164
Merged
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
49f7b73
Add basic docs
Ifropc 0d552bd
SEP-10 docs
Ifropc 8574dc6
Add server side implementation
Ifropc 1d87aff
Small refactoring
Ifropc 83e0d1d
SEP-24 skeleton
Ifropc c7a268a
Interactive documentation
Ifropc c169b87
Small change
Ifropc 921ce62
Add watcher and get transaction docs
Ifropc 96a7e01
Finish documentation
Ifropc 4b4062e
Prettifying
Ifropc 184bc6c
Small additions
Ifropc 901e6dc
Move docs
Ifropc ffeaa86
grammatical fixes
briwylde08 8dfe337
grammatical fixes
briwylde08 909d270
grammatical fixes
briwylde08 a5eb91a
grammatical fixes
briwylde08 feccc15
grammatical fixes
briwylde08 e1aba3b
formatting
briwylde08 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "Become 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,167 @@ | ||
--- | ||
title: Getting Started | ||
sidebar_position: 20 | ||
--- | ||
|
||
import { CodeExample } from "@site/src/components/CodeExample"; | ||
|
||
In this guide we will use 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 app. Creating wallet with default configuration connected to testnet is simple: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val wallet = Wallet(StellarConfiguration.Testnet) | ||
``` | ||
|
||
</CodeExample> | ||
|
||
The wallet instance can be further configured. For example, to connect to public main network: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val walletMainnet = Wallet(StellarConfiguration(Network.PUBLIC, "https://horizon.stellar.org")) | ||
``` | ||
|
||
</CodeExample> | ||
|
||
There is one more available configuration for wallet that allows to configure internal logic of the SDK. For example, to test with local servers on http protocol, http can be manually enabled. | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val walletCustom = Wallet( | ||
StellarConfiguration.Testnet, | ||
ApplicationConfiguration { defaultRequest { url { protocol = URLProtocol.HTTP } } } | ||
) | ||
``` | ||
|
||
</CodeExample> | ||
|
||
### Configuring 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 10 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 app), in other cases it can be required. If your wallet class is short-lived, it's recommended to close client resources using close function: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
fun closeWallet() { | ||
wallet.close() | ||
} | ||
``` | ||
|
||
</CodeExample> | ||
|
||
## Stellar Basics | ||
|
||
Wallet SDK provides some extra functionality on top of existing [Horizon SDK]. For interaction with the Stellar network, SDK covers only basics, used in a typical wallet flow. For more advanced use cases underlying [Horizon SDK] should be used instead. | ||
|
||
To interact with Horizon instance configured in previous steps, simply do: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
val stellar = wallet.stellar() | ||
``` | ||
|
||
</CodeExample> | ||
|
||
This example will create a Stellar class, that manages connection to Horizon service. | ||
|
||
:::note | ||
|
||
Default configuration connects to public Stellar Horizon instance. You can change this behavior as described [above](#working-with-the-sdk) | ||
|
||
::: | ||
|
||
You can read more about working with Stellar network in the [respective section](./stellar.mdx). | ||
|
||
## Anchor Basics | ||
|
||
Primarily 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 [SEP-1] info file: | ||
|
||
<CodeExample> | ||
|
||
```kotlin | ||
suspend fun anchorToml(): TomlInfo { | ||
return anchor.getInfo() | ||
} | ||
``` | ||
|
||
</CodeExample> | ||
|
||
Anchor class also supports [stellar authentication] ([SEP-10]) and [hosted deposit and withdrawal] ([SEP-24]) 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 | ||
[stellar authentication]: ./sep10.mdx | ||
[hosted deposit and withdrawal]: ./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? | ||
|
||
Wallet in application that allows its user to hold assets, such as native Stellar 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 vs. Non-Custodial Applications | ||
|
||
Some applications, such as centralized exchanges, are custodial, meaning the application has access to the private keys of the acccounts 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 MoneyGram Access. 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets remove the reference to MoneyGram and replace it with a generic reference to anchors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah a lot of it is copy-paste...
I want to re-word and refactor it later when I have a chance to do so