> 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-conversions-with-anchor-chaining.md).

# Fiat Conversions With Anchor Chaining

This example shows how to use the Anchor Chaining SDK to perform fiat conversions.  FX via an external fiat anchor may require additional steps than just a simple FX Anchor.  The Anchor Chaining library helps facilitate the steps required (eg. CAD to EUR may require CAD to USD then USD to EUR). \
This example assumes KYC has been completed and onboarded wtih a fiat anchor that supports USD and EUR and that the account has existing USD balance.&#x20;

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`
* Use the main network Keeta EUR Token - `keeta_anutgo4o3yp5tvc6wjt4vzsehjbn7t2wylpxmam4d4ojtdkjj2yca2qoinfcs`

{% 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);
```

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

{% step %}

### Initialize Anchor Chaining

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

```ts
	const anchorChaining = new AnchorChaining({
		client: userClient
	});
```

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

{% step %}

### Construct the Conversion Request

This example performs a conversion between USD and EUR for $2.00

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

```ts
	const keetaLocation = `chain:keeta:${userClient.network}` as const;
	const conversionRequest = {
		source: {
			asset: Account.fromPublicKeyString('keeta_any4zllibya6fum3lsoimxmnmeo57nklxlh4c6d6xosfacarfaa3knkiprkmm');,
			location: keetaLocation,
			value: 200n,
			rail: 'KEETA_SEND' as const
		},
		destination: {
			asset: Account.fromPublicKeyString('keeta_amqsghqea5mv2476c44ahgt7xbawms5z76d7ffbzirkp56t2hn4bahoqljqeg');,
			location: keetaLocation,
			recipient: account.publicKeyString.get(),
			rail: 'KEETA_SEND' as const
		}
	};
```

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

{% step %}

### Search Available Paths

Searching the available anchor paths uses the Anchor Resolver metadata to determine what anchor's currently support the desired request and what paths can be used to get from source to destination.

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

```ts
const paths = await anchorChaining.getPaths(conversionRequest);
```

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

{% step %}

### Compute Plans

Getting the plans involves contacting each Anchor required to perform the request and obtaining the instructions for each step of the plan.

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

```ts
const plans = await anchorChaining.getPlans(conversionRequest);
```

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

{% step %}

### Execute the Plan

The Anchor Chaining library automatically generates the necessary blocks required to send from the users account to the anchor to perform the swaps.

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

```ts
const conversion = await plan.execute();
```

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

{% step %}

### Confirm Balance Updates

Once the conversion is completed balance changes can be viewed directly from the network

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

```ts
const allBalances = await userClient.allBalances()
```

{% 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-fx.ts>" %}
{% 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.keeta.com/guides/fiat-conversions-with-anchor-chaining.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
