> For the complete documentation index, see [llms.txt](https://docs.keeta.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.keeta.com/guides/fiat-deposit-from-bank.md).

# Fiat Deposit from Bank

This example shows how to obtain bank deposit information from an Anchor that supports inbound payments that are minted on Keeta.  It assumes KYC has already been completed and shared with the Anchor.  See the two KYC guides [Add KYC Certificate](https://app.gitbook.com/o/qYWvPguljbNCiIZoKq7U/sites/site_VPB12/s/pitcpcamWc0BKEe28I1D/~/edit/~/changes/85/guides/add-kyc-certificate) and [Share KYC Attributes](https://app.gitbook.com/o/qYWvPguljbNCiIZoKq7U/sites/site_VPB12/s/pitcpcamWc0BKEe28I1D/~/edit/~/changes/85/guides/share-kyc-attributes) for more details on handling KYC.

To run the example on the main network, the following changes are needed.

* Change network from `test` to `main`
* Use the main network Keeta USD Token - `keeta_amnkge74xitii5dsobstldatv3irmyimujfjotftx7plaaaseam4bntb7wnna`

{% stepper %}
{% step %}

### Setup Account and Anchor Client

{% tabs %}
{% tab title="TypeScript" %}
{% code expandable="true" %}

```ts
const account = Account.fromSeed(seed.trim(), 0);
await using userClient = KeetaAnchor.KeetaNet.UserClient.fromNetwork('test', account);
const assetMovementClient = new KeetaAnchor.AssetMovement.Client(userClient);
```

{% endcode %}
{% endtab %}

{% tab title="C#" %}
{% code expandable="true" %}

```csharp
using Account userAccount = runtime.Accounts.FromSeed(seed, 0, "ecdsa_secp256k1");

UserClient userClient = UserClient.FromNetwork("test", userAccount);
using AssetMovementClient assetMovementClient = runtime.CreateAssetMovementClient(
  Constants.NodeApi,
	userClient.NetworkAddress,
	userAccount);
```

{% endcode %}
{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### Establish Source Location and Destination

{% tabs %}
{% tab title="TypeScript" %}
{% code expandable="true" %}

```ts
const KEETA_USD_ASSET = Account.fromPublicKeyString('keeta_any4zllibya6fum3lsoimxmnmeo57nklxlh4c6d6xosfacarfaa3knkiprkmm');
const US_BANK_SOURCE = { type: 'bank-account', account: { type: 'us' }} as const;

const keetaDestination = {
	type: 'chain',
	chain: { type: 'keeta', networkId: userClient.network }
} as const;

const assetPair = { from: 'USD' as const, to: KEETA_USD_ASSET };
```

{% endcode %}
{% endtab %}

{% tab title="C#" %}
{% code expandable="true" %}

```csharp
string KeetaUsdAsset = "keeta_any4zllibya6fum3lsoimxmnmeo57nklxlh4c6d6xosfacarfaa3knkiprkmm";
string BankAccountUsLocation = "bank-account:us";
string keetaDestination = $"chain:keeta:{userClient.Network}";

AssetOrPair assetPair = AssetOrPair.Pair("USD", KeetaUsdAsset);
```

{% endcode %}
{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### Identify Provider with Anchor Resolver

{% tabs %}
{% tab title="TypeScript" %}
{% code expandable="true" %}

```ts
const providers = await assetMovementClient.getProvidersForTransfer({
	asset: assetPair,
	from: US_BANK_SOURCE,
	to: keetaDestination
});
```

{% endcode %}
{% endtab %}

{% tab title="C#" %}
{% code expandable="true" %}

```csharp
IReadOnlyList<AssetProvider> providers = await assetMovementClient.GetProvidersForTransfer(
  new AssetProviderSearch(
    Asset: assetPair,
    From: BankAccountUsLocation,
    To: keetaDestination),
cancellationToken);
```

{% endcode %}
{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### Request Deposit Information

{% tabs %}
{% tab title="TypeScript" %}
{% code expandable="true" %}

```ts
const depositInfo = await provider.createPersistentForwardingAddress({
	account,
	asset: assetPair,
	sourceLocation: US_BANK_SOURCE,
	destinationLocation: keetaDestination,
	destinationAddress: account.publicKeyString.get()
});
```

{% endcode %}
{% endtab %}

{% tab title="C#" %}
{% code expandable="true" %}

```csharp
JsonElement depositInfo = await assetMovementClient.CreatePersistentForwardingAddress(
  provider,
  request,
  cancellationToken);
```

{% endcode %}
{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

### Make an ACH Payment and Check Balance

There are multiple ways to check if an account has changed.  Simplest is to query the account balance for a given token.

{% tabs %}
{% tab title="TypeScript" %}
{% code expandable="true" %}

```ts
const accountUSDBalance = await userClient.balance(KEETA_USD_ASSET);
```

{% endcode %}
{% endtab %}

{% tab title="C#" %}
{% code expandable="true" %}

```csharp
using Account usdToken = runtime.Accounts.FromPublicKeyString(Constants.KeetaUsdAsset);
BigInteger currentBalance = await nodeClient.GetAccountBalance(userAccount, usdToken, cancellationToken);
```

{% endcode %}
{% endtab %}
{% endtabs %}

Alternatively, can poll the account history to identify changes affecting the account

{% tabs %}
{% tab title="TypeScript" %}
{% code expandable="true" %}

```ts
const accountHistory = await userClient.history();
```

{% endcode %}
{% endtab %}
{% endtabs %}

Lastly, the UserClient has a change callback that can be implemented to connect via websocket and listen for changes.  It also uses a periodic polling fallback in case the websocket disconnects.

{% tabs %}
{% tab title="TypeScript" %}
{% code expandable="true" %}

```ts
const userClientChangeListener = userClient.on('change', function(data) {
   console.log(data);
});
```

{% endcode %}
{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

## Full Code Example

{% tabs %}
{% tab title="TypeScript" %}
{% @github-files/github-code-block url="<https://github.com/KeetaNetwork/keetanet-examples/blob/main/src/anchor/asset-movement-fiat-deposit-from-bank.ts>" %}
{% endtab %}

{% tab title="C#" %}
{% @github-files/github-code-block url="<https://github.com/KeetaNetwork/keetanet-examples/blob/main/csharp/src/Anchor/AssetMovementFiatDepositFromBank.cs>" %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.keeta.com/guides/fiat-deposit-from-bank.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
