Skip to content
Docs

Platforms

Bare React Native

Set up the wallet SDKs in a bare React Native app with Hermes, CocoaPods, and a storage backend.

Requirements

React Native 0.74 or later with Hermes. The steps match Expo, with the differences below.

1. Install

Package manager
npm install @gray3/client @gray3/keystore react-native-get-random-values
bash
cd ios && pod install && cd ..

2. Polyfills and entry file

js
// polyfills.js
import "react-native-get-random-values"; // must be first
// If GrayClient.create reports TextDecoder missing: npm install fast-text-encoding, then
// import "fast-text-encoding";
js
// index.js
import "./polyfills";
import { AppRegistry } from "react-native";
import App from "./App";
import { name as appName } from "./app.json";

AppRegistry.registerComponent(appName, () => App);

3. Metro configuration

Metro resolves package exports by default from React Native 0.79. On 0.74–0.78 enable it so the React Native builds of @gray3/client and @gray3/keystore are used.

js
// metro.config.js
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");

module.exports = mergeConfig(getDefaultConfig(__dirname), {
  resolver: { unstable_enablePackageExports: true }, // React Native 0.74–0.78
});

4. Choose a storage backend

The React Native build of @gray3/keystore supports three backends.

FieldRequiredDescription
sqlite: { expo }NoRecommended. expo-sqlite works in bare apps once Expo Modules are installed (npx install-expo-modules@latest, then npx expo install expo-sqlite).
adapter: asyncKvAdapter(…)NoWrap any async key-value store, such as AsyncStorage. Suitable for small wallet counts, because the wallet list is rewritten on each change.
sqlite: { driver }NoYour own synchronous SQLite driver with exec(sql), prepare(sql) returning { run, get, all }, and an optional transaction(fn).
js
// Option A: expo-sqlite (with Expo Modules installed)
import * as SQLite from "expo-sqlite";
import { GrayKeystore } from "@gray3/keystore";

const storage = await GrayKeystore.create({
  sqlite: { expo: SQLite.openDatabaseSync("gray-wallets.db") },
  password: pin,
});

// Option B: AsyncStorage through asyncKvAdapter
import AsyncStorage from "@react-native-async-storage/async-storage";
import { GrayKeystore, asyncKvAdapter } from "@gray3/keystore";

const storage = await GrayKeystore.create({
  adapter: asyncKvAdapter({
    getItem: (k) => AsyncStorage.getItem(k),
    setItem: (k, v) => AsyncStorage.setItem(k, v),
    removeItem: (k) => AsyncStorage.removeItem(k),
    getAllKeys: () => AsyncStorage.getAllKeys(),
  }),
  password: pin,
});

5. Client, wallet, and backend calls

js
import { GrayClient } from "@gray3/client";

const client = await GrayClient.create({ storage });

// Create a new wallet (or import an existing phrase)
const wallet = await client.wallets.create({ label: "Main", password: pin });
// const wallet = await client.wallets.importMnemonic({ mnemonic, label: "Restored", password: pin });

// Addresses are derived on the device
const account = wallet.account(0);
const evmAddress = account.address("ethereum");
const solAddress = account.address("solana");

// Sign a message; the result names the signing standard
const { signature, address, standard } = await account.signMessage("Hello from Gray3", "ethereum");
// standard === "eip191"
js
// Your backend URL — it holds the secret key, the app never does
const API = "https://api.example.com";

const res = await fetch(`${API}/portfolio?chainId=ethereum&address=${evmAddress}`, {
  headers: { authorization: `Bearer ${userSessionToken}` }, // your own user auth
});
const body = await res.json();
if (body.error) throw new Error(`${body.error.code}: ${body.error.message}`);
const portfolio = body.data;

Gram signing, PIN handling, and limits

Gram (TON) signing, key mode with a secure-storage key, and the Monero, Kaspa, and Polkadot notes are the same as for Expo. See Gram (TON) signing, Protecting the PIN, and Limits on React Native. In a bare app, use the Metro configuration from step 3 instead of expo/metro-config, and use a Keychain or Keystore library such as react-native-keychain in place of expo-secure-store.