# TypeScript + Viem

> Step-by-step TypeScript guides for Flare Smart Accounts using Viem, XRPL, and the Flare Data Connector.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown versions of documentation pages are available by appending `.md` to the page URL.

Source: https://dev.flare.network/smart-accounts/guides/typescript-viem

These guides walk through [Flare Smart Accounts](/smart-accounts/overview) flows with [Viem](https://viem.sh/) and the [xrpl](https://js.xrpl.org/) library on [**Coston2** network](/network/overview). Each guide includes a runnable script from the [flare-viem-starter](https://github.com/flare-foundation/flare-viem-starter) repository.

Start with [State Lookup](/smart-accounts/guides/typescript-viem/state-lookup-ts) to derive your personal account address from an XRPL wallet, then follow the [custom-instruction](/smart-accounts/guides/typescript-viem/custom-instruction-ts) or [cross-chain](/smart-accounts/guides/typescript-viem/cross-chain-mint-ts) guides depending on your integration.

## Getting Started[​](#getting-started "Direct link to Getting Started")

Read the on-chain smart-account state before sending XRPL payments.

[

## State Lookup

Reading the smart-accounts-related states from the Flare chain using Viem.

](/smart-accounts/guides/typescript-viem/state-lookup-ts)

## Custom Instructions[​](#custom-instructions "Direct link to Custom Instructions")

Mint FXRP and dispatch user operations through XRPL memo opcodes (`0xFE`, `0xFF`), recover when a direct mint fails (`0xE0`), and fast-forward a stuck memo-instruction nonce (`0xE1`).

[

## Custom Instruction

Sending custom smart account instructions via XRPL using Viem and an off-chain executor.

](/smart-accounts/guides/typescript-viem/custom-instruction-ts)

[

## Memo Field Custom Instruction

Sending the full PackedUserOperation in an XRPL memo with Viem (0xFF flow).

](/smart-accounts/guides/typescript-viem/memo-field-custom-instruction-ts)

[

## Recover Stuck Mint Transaction

Recover FXRP when a smart-account direct mint reverted or was never finalized, using the 0xE0 skip-memo flow with Viem.

](/smart-accounts/guides/typescript-viem/recover-stuck-mint-transaction-ts)

[

## Fast-Forward Nonce

Advance a personal account's memo-instruction nonce when it is stuck after a partial or abandoned direct-mint flow, using the 0xE1 opcode with Viem.

](/smart-accounts/guides/typescript-viem/fast-forward-nonce-ts)

## Cross-Chain[​](#cross-chain "Direct link to Cross-Chain")

Bridge FXRP between Flare and Sepolia with LayerZero OFT adapters, combining mint or redeem with a cross-chain transfer in one flow.

[

## Cross-Chain Mint

Mint FXRP from XRP and bridge it to Sepolia in a single XRPL payment using Viem, LayerZero, and the Custom Instruction (0xFE).

](/smart-accounts/guides/typescript-viem/cross-chain-mint-ts)

[

## Cross-Chain Redeem

Send FXRP from Sepolia back to Flare and auto-redeem it to XRP on the XRPL using Viem and LayerZero.

](/smart-accounts/guides/typescript-viem/cross-chain-redeem-ts)

[

## Cross-Chain Redeem to Tag

Send FXRP from Sepolia back to Flare and auto-redeem to an XRPL address with a destination tag.

](/smart-accounts/guides/typescript-viem/cross-chain-redeem-to-tag-ts)

## Token Interactions[​](#token-interactions "Direct link to Token Interactions")

Move ERC-20 balances held by a personal account with fee-only `0xFE` custom instructions (no FXRP mint).

[

## Control USDT0

Transfer and swap USDT0 from a Flare personal account using fee-only 0xFE custom instructions with Viem.

](/smart-accounts/guides/typescript-viem/control-usdt0-ts)

Protocol reference

For opcode layouts and failure handling without code, see [Custom Instruction](/smart-accounts/custom-instruction), [Memo Field Custom Instruction](/smart-accounts/memo-field-custom-instruction), and [Custom Instruction Comparison](/smart-accounts/custom-instruction-comparison).
