deposit method

Future<DepositResponse> deposit(
  1. DepositRequest request
)

A deposit is when a user sends an external token (BTC via Bitcoin, USD via bank transfer, etc...) to an address held by an anchor. In turn, the anchor sends an equal amount of tokens on the Stellar network (minus fees) to the user's Stellar account.

If the anchor supports SEP-38 quotes, it can also provide a bridge between non-equivalent tokens. For example, the anchor can receive ARS via bank transfer and in return send the equivalent value (minus fees) as USDC on the Stellar network to the user's Stellar account. That kind of deposit is covered in GET /deposit-exchange.

The deposit endpoint allows a wallet to get deposit information from an anchor, so a user has all the information needed to initiate a deposit. It also lets the anchor specify additional information (if desired) that the user must submit via SEP-12 to be able to deposit.

Implementation

Future<DepositResponse> deposit(DepositRequest request) async {
  Uri serverURI =
      Util.appendEndpointToUrl(_transferServiceAddress, 'deposit');

  _DepositRequestBuilder requestBuilder =
      _DepositRequestBuilder(httpClient, serverURI);

  final Map<String, String> queryParams = {
    "asset_code": request.assetCode,
    "account": request.account,
  };

  if (request.memoType != null) {
    queryParams["memo_type"] = request.memoType!;
  }
  if (request.memo != null) {
    queryParams["memo"] = request.memo!;
  }
  if (request.emailAddress != null) {
    queryParams["email_address"] = request.emailAddress!;
  }
  if (request.type != null) {
    queryParams["type"] = request.type!;
  }
  if (request.walletName != null) {
    queryParams["wallet_name"] = request.walletName!;
  }
  if (request.walletUrl != null) {
    queryParams["wallet_url"] = request.walletUrl!;
  }
  if (request.lang != null) {
    queryParams["lang"] = request.lang!;
  }
  if (request.onChangeCallback != null) {
    queryParams["on_change_callback"] = request.onChangeCallback!;
  }
  if (request.amount != null) {
    queryParams["amount"] = request.amount!;
  }
  if (request.countryCode != null) {
    queryParams["country_code"] = request.countryCode!;
  }
  if (request.claimableBalanceSupported != null) {
    queryParams["claimable_balance_supported"] =
        request.claimableBalanceSupported!;
  }
  if (request.customerId != null) {
    queryParams["customer_id"] = request.customerId!;
  }
  if (request.locationId != null) {
    queryParams["location_id"] = request.locationId!;
  }

  try {
    return await requestBuilder
        .forQueryParameters(queryParams)
        .execute(request.jwt);
  } on ErrorResponse catch (e) {
    if (e.code == 403) {
      _handleForbiddenResponse(e);
    }
    throw e;
  }
}