Helps clients to interact with anchors in a standard way defined by SEP-0006: Deposit and Withdrawal API.
By providing the domain hosting the stellar.toml file
let responseEnum = await TransferServerService.forDomain(domain: "https://YOUR_DOMAIN")
switch responseEnum {
case .success(let service):
// use the service object to call operations
case .failure(_):
// something went wrong
}
This will automatically load and parse the stellar.toml file. It will then create the TransferServerService instance by using the transfer server url provided in the stellar.toml file.
Or by providing the service url
Alternatively one can create a TransferServerService instance by providing the transfer server url directly via the constructor:
let service = TransferServerService(
serviceAddress: "http://api.stellar-anchor.org/transfer"
)
This endpoint (described here) allows an anchor to communicate basic info about what their TRANSFER_SERVER supports to wallets and clients. With the ios sdk you can use the info
method of your TransferServerService
instance to get the info:
let responseEnum = await service.info()
switch responseEnum {
case .success(let info):
// success
case .failure(_):
// something went wrong
}
This endpoint (described here) is used when a user sends an external token (BTC via Bitcoin, USD via bank transfer, etc...) to an address held by an anchor. With the ios sdk you can use the deposit
method of your TransferServerService
instance to get the deposit information:
let request = DepositRequest(
assetCode: "USD",
account: "GAK7I2E6PVBFF27NU5MRY6UXGDWAJT4PF2AH46NUWLFJFFVLOZIEIO4Q",
jwt: jwtToken
)
let responseEnum = await service.deposit(request: request)
switch responseEnum {
case .success(let response):
// success
case .failure(_):
// something went wrong
}
This endpoint (described here) is used when a user redeems an asset currently on the Stellar network for it's equivalent off-chain asset via the Anchor. For instance, a user redeeming their NGNT in exchange for fiat NGN. With the ios sdk you can use the withdraw
method of your TransferServerService
instance to get the withdrawal information:
let request = WithdrawRequest(
type: "bank_account",
assetCode: "NGNT",
jwt: jwtToken
)
let responseEnum = await service.withdraw(request: request)
switch responseEnum {
case .success(let response):
// success
case .failure(_):
// something went wrong
}
If the anchor supports SEP-38 quotes, it can provide a deposit that makes a bridge between non-equivalent tokens by receiving, for instance BRL via bank transfer and in return sending the equivalent value (minus fees) as USDC to the user's Stellar account.
The /deposit-exchange endpoint allows a wallet to get deposit information from an anchor when the user intends to make a conversion between non-equivalent tokens. With this endpoint, described here, a user has all the information needed to initiate a deposit and it also lets the anchor specify additional information (if desired) that the user must submit via SEP-12.
let request = DepositExchangeRequest(
destinationAsset: "USDC",
sourceAsset: "iso4217:BRA",
amount: "480",
account: "GDIODQRBHD32QZWTGOHO2MRZQY2TRG5KTI2NNTFYH2JDYZGMU3NJVAUI"
)
let responseEnum = await service.depositExchange(request: request)
switch responseEnum {
case .success(let response):
// success
case .failure(_):
// something went wrong
}
If the anchor supports SEP-38 quotes, it can provide a withdraw that makes a bridge between non-equivalent tokens by receiving, for instance USDC from the Stellar network and in return sending the equivalent value (minus fees) as NGN to the user's bank account.
The /withdraw-exchange endpoint allows a wallet to get withdraw information from an anchor when the user intends to make a conversion between non-equivalent tokens. With this endpoint, a user has all the information needed to initiate a withdraw and it also lets the anchor specify additional information (if desired) that the user must submit via SEP-12.
let request = WithdrawExchangeRequest(
sourceAsset: "USDC",
destinationAsset: "iso4217:NGN",
amount: "700",
type: "bank_account"
)
let responseEnum = await service.withdrawExchange(request: request)
switch responseEnum {
case .success(let response):
// success
case .failure(_):
// something went wrong
}
This endpoint (described here) allows an anchor to report the fee that would be charged for a given deposit or withdraw operation. With the ios sdk you can use the fee
method of your TransferServerService
instance to get the info if supported by the anchor:
let request = FeeRequest(
operation: "deposit",
assetCode: "NGN",
amount: 123.09
)
let responseEnum = await service.fee(request: request)
switch responseEnum {
case .success(let response):
// success
case .failure(_):
// something went wrong
}
From this endpoint (described here) wallets can receive the status of deposits and withdrawals while they process and a history of past transactions with the anchor. With the ios sdk you can use the getTransactions
method of your TransferServerService
instance to get the transactions:
let request = AnchorTransactionsRequest(
assetCode: "XLM",
account: "GCTTGO5ABSTHABXWL2FMHPZ2XFOZDXJYJN5CKFRKXMPAAWZW3Y3JZ3JK",
jwt: jwtToken)
let responseEnum = await service.getTransactions(request: request)
switch responseEnum {
case .success(let response):
// success
case .failure(_):
// something went wrong
}
This endpoint (described here) enables clients to query/validate a specific transaction at an anchor. With the ios sdk you can use the getTransaction
method of your TransferServerService
instance to get the data:
let request = AnchorTransactionRequest(
id:"82fhs729f63dh0v4",
jwt: jwtToken
)
let responseEnum = await service.getTransaction(request: request)
switch responseEnum {
case .success(let response):
// success
case .failure(_):
// something went wrong
}
For more info, see also the sdk's SEP-0006 test cases.