@satoshipay/stellar-transfer
Stellar Ecosystem Proposal 24 - "Anchor/Client interoperability" client SDK, allowing Stellar wallets to withdraw or deposit third-party fiat or crypto assets like USD, EURT, BTC, ETH, ...
That means that users can send EURT to the anchor, requesting a payout in fiat EUR to their SEPA account via bank transfer, for instance.
Installation
npm install @satoshipay/stellar-transfer
# or with yarn:
yarn add @satoshipay/stellar-transfer
Concepts
- Deposit - Send some value outside the Stellar network to the anchor who will send us tokens on the Stellar network
- KYC (Know your customer) - Prove your identity to the anchor to meet anti-money-laundering regulations
- Transfer server - That is the anchor's service responsible for deposit/withdrawal of tokens
- Withdrawal - Send tokens on the Stellar network to its anchor who will pay us out outside the Stellar network
Usage
Fetch transfer server metadata
import {
openTransferServer,
fetchTransferInfos,
TransferServer
} from "@satoshipay/stellar-transfer"
import { Networks } from "stellar-sdk"
const transferServer = await openTransferServer(
"www.anchorusd.com",
Networks.TESTNET,
{
lang: "en",
wallet_name: "Demo wallet",
wallet_version: "1.2.3"
}
)
const transferInfos = await fetchTransferInfos(transferServer)
const { depositableAssets, withdrawableAssets } = transferInfos
console.log(
`Depositable assets: ${depositableAssets
.map(asset => asset.getCode())
.join(", ")}`
)
console.log(
`Withdrawable assets: ${withdrawableAssets
.map(asset => asset.getCode())
.join(", ")}`
)
Request a withdrawal
import {
openTransferServer,
KYCResponseType,
TransferResultType,
TransferServer,
Withdrawal,
WithdrawalType
} from "@satoshipay/stellar-transfer"
import { Networks } from "stellar-sdk"
const transferServer = await openTransferServer(
"www.anchorusd.com",
Networks.TESTNET
)
const transferInfos = await fetchTransferInfos(transferServer)
const { withdrawableAssets } = transferInfos
const assetToWithdraw = withdrawableAssets.find(asset => asset.code === "USD")
const withdrawal = Withdrawal(transferServer, assetToWithdraw, {
type: WithdrawalType.bankAccount,
dest: "DE00 1234 5678 9012 3456 00",
dest_extra: "NOLADEXYZ"
})
const instructions = await withdrawal.interactive(
sep10AuthToken
)
if (instructions.type === TransferResultType.ok) {
} else if (
instructions.type === TransferResultType.kyc &&
instructions.subtype === KYCResponseType.interactive
) {
} else if (
instructions.type === TransferResultType.kyc &&
instructions.subtype === KYCResponseType.nonInteractive
) {
} else if (
instructions.type === TransferResultType.kyc &&
instructions.subtype === KYCResponseType.status
) {
if (instructions.data.status === "pending") {
} else if (instructions.data.status === "denied") {
throw Error(
`KYC has failed. Get more details here: ${
instructions.data.more_info_url
}`
)
}
}
Bulk operations
import {
fetchAssetTransferInfos,
fetchTransferServers,
TransferInfo
} from "@satoshipay/stellar-transfer"
import { Asset, Server } from "stellar-sdk"
const assets = [
new Asset("EURT", "GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S"),
new Asset("USD", "GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX")
]
const horizon = new Server("https://stellar-horizon.satoshipay.io/")
const assetTransferServers: Map<
Asset,
TransferServer | null
> = await fetchTransferServers(horizon, assets)
const assetTransferInfos: Map<
Asset,
AssetTransferInfo
> = await fetchAssetTransferInfos(assetTransferServers)
interface AssetTransferInfo {
deposit: TransferInfo["deposit"][""]
transferInfo: TransferInfo
withdraw: TransferInfo["withdraw"][""]
}
Response types
We provide TypeScript type declarations for all responses of the /info
, /deposit
& /withdraw
endpoints. See src/responses.ts
.
License
GPL v3