Skip to main content

What you will learn

  • How to import an Anchor Program into a React Native project
  • How to create an Anchor Wallet and Provider with Mobile Wallet Adapter
  • How to sign and submit transactions with an Anchor Program IDL
  • How to generate instructions with an Anchor Program IDL

Prerequisites

Installation

Add the Anchor library to your React Native Project:
CAUTIONReact Native apps should use Anchor v0.28.0 because later versions of the library have a polyfill issue on React Native.

Create an Anchor Wallet with Mobile Wallet Adapter

TIPThe Anchor Counter Program example app shows how to create an Anchor wallet that is integrated with a more complex state management framework.
To create an AnchorWallet, use Mobile Wallet Adapter transact to implement the required signing functions. A simple implementation:

Importing an Anchor Program in Typescript

Generating an Anchor Program IDL

If you have an Anchor project in your local workspace, build the program and generate the Typescript IDL with:
If the Anchor program is already deployed and you know its address, you can use the Anchor CLI to fetch it:

Instantiate your Anchor Program

Once your IDL has been generated, you can import it and create an instance of your Program in Typescript.
  • Import your generated IDL file, in this case from /target/types/basic_counter.ts
  • Use the anchorWallet from the previous step to create an AnchorProvider.

Sign transactions manually with Mobile Wallet Adapter

With an instantiated Program, you can:
  • Generate serialized program instructions.
  • Construct a Transaction with the generated instructions.
  • Manually sign the Transaction with Mobile Wallet Adapter.
In the following example, we generate an incrementInstruction from the program then sign it within a Mobile Wallet Adapter session.
This approach is flexible and allows you to fully utilize the Mobile Wallet Adapter session.

Sign transactions using a Mobile Wallet Adapter signer

With an instantiated Program, you can also use the Anchor provided rpc() function to sign and submit an Anchor transaction to an RPC.
Calling the rpc() will generate and sign the transaction using the interface methods (signTransaction, signAllTransactions) of the Anchor Wallet that the program was instantiated with.

Generating Clients with Codama

Use Codama to generate TypeScript client code from your Anchor IDL.

1. Ensure your Anchor IDL exists

This should produce an IDL under target/idl/.... Place the file where your codama.json points (example below uses program/idl.json).

2. Install dependencies

3. Add codama.json (project root)

Why these fields exist:
  • idl: Tells Codama which Anchor IDL file to read.
  • scripts.js.from: Tells Codama which renderer to run (TypeScript/JS client renderer).
  • scripts.js.args: Renderer arguments. For @codama/renderers-js, the first value is the output directory for generated files.
  • before: Optional transform pipeline before rendering (empty here).

4. Generate code

5. Output structure

Generated files are written to the output directory set in scripts.js.args. With the config above:
Last modified on July 21, 2026