Skip to content

React Native SDK

The SLIM React Native SDK (@agntcy/slim-bindings-react-native) provides mobile and browser APIs for building applications on SLIM. Bindings are generated from the same Rust core as every other language binding via uniffi-bindgen-react-native, with native integration for iOS and Android and a WebAssembly build for browsers.

For Node.js servers, CLI tools, and non-mobile JavaScript applications, use @agntcy/slim-bindings instead.

Requirements

Native targets iOS, Android (React Native)
Web target Modern browsers with WebAssembly support
Package @agntcy/slim-bindings-react-native on npm
Build tools Node.js 18+, Rust 1.70+ (for building from source)
Examples react-native/examples in slim-bindings

Installation

npm install @agntcy/slim-bindings-react-native
yarn add @agntcy/slim-bindings-react-native

After installing in a React Native project, run the iOS pod install step:

cd ios && pod install

Getting Started

The SDK tutorials build a full application step by step — initialising the service, connecting to a node, creating an app, opening sessions, receiving messages, and adding persistence — with React Native snippets shown alongside every other binding. They target the native (iOS/Android) build; the browser quick start below covers the WebAssembly entry point.

Start with Connecting to SLIM.

Browser / WebAssembly Quick Start

Browser builds connect over ws:// or wss:// and use a separate entry point. Call uniffiInitAsync() once before using the bindings:

import {
  App,
  Direction,
  Name,
  SessionType,
  uniffiInitAsync,
} from '@agntcy/slim-bindings-react-native/web';

await uniffiInitAsync();

const local = new Name('org', 'default', 'browser');
const remote = new Name('org', 'default', 'agent');

const app = await App.connectWithSecret(
  'wss://slim.example/ws',
  undefined,
  local,
  'change-me-before-going-to-production',
  Direction.Bidirectional,
);

await app.setRouteViaUpstreamAsync(remote);
const session = await app.createSessionAndWaitAsync(
  {
    sessionType: SessionType.PointToPoint,
    maxRetries: 10,
    interval: undefined,
    metadata: new Map(),
    mlsSettings: undefined,
  },
  remote,
);

await session.publishAndWaitAsync(
  new TextEncoder().encode('Hello, SLIM!'),
  'text/plain',
  undefined,
);

All operations that wait for network or session state must use their async variants in browsers.

API Overview

Type Description
Default export / /web entry Static entry point for initialisation and global service access
App Application handle for sessions, subscriptions, and routing
BindingsSessionContext Session for sending and receiving messages
Name Identity in org/namespace/app format
ReceivedMessage Received message with payload and context metadata
SessionConfig Session configuration (type, MLS, retries)
SessionType PointToPoint or Group

On the native (iOS/Android) target, the gRPC client and server configurations expose transport authentication via config.auth, matching the Node.js SDK. On the web/WebAssembly target, gRPC configuration is absent by design — browser apps connect over WebSocket and authenticate through the identity path instead.

Call app.destroy() when finished to release native resources.

Session Configuration (Native)

const sessionConfig: slimBindings.SessionConfig = {
  sessionType: slimBindings.SessionType.PointToPoint,
  metadata: new Map(),
  mlsSettings: { headerIntegrityValidationPercent: 100 },
};

const session = await app.createSessionAndWaitAsync(sessionConfig, remoteName);

Annotate the object as SessionConfig rather than typing it any — that is what catches an unknown field, which is otherwise accepted and silently ignored. metadata is required, maxRetries and interval fall back to the SLIM defaults, and omitting mlsSettings disables MLS.

Transport Authentication

On the native (iOS/Android) target, transport authentication via OIDC and other gRPC auth modes matches the Node.js SDK. See the Node.js transport authentication section for code snippets and the JSON config form.

On the web/WebAssembly target, the browser build compiles out the gRPC configuration module (ClientConfig, TlsClientConfig, ClientAuthenticationConfig, and therefore OIDC). Browser apps authenticate through the shared-secret, JWT, or SPIRE identity path instead.

Examples

The slim-bindings/react-native directory includes:

Example Description
examples/react-native/test-app React Native test app for iOS and Android
examples/browser Browser playground for unicast, multicast, and MLS

Browser playground:

cd react-native
npm install
npm run build:web
cd examples/browser
npm install
npm run dev

See examples/browser/README.md for point-to-point, group, and MLS walkthroughs.

Platform Support

Target Platform Status
Native iOS Supported
Native Android Supported
Web Browsers with WASM Supported

Building from Source

To build the React Native SDK from the slim-bindings repository:

git clone https://github.com/agntcy/slim-bindings
cd slim-bindings/react-native

npm install
task generate
task generate:web
task test

For iOS build issues, refresh the XCFramework and pods:

task prepare:ios
cd examples/react-native/test-app/ios && pod install

Open TestApp.xcworkspace (not .xcodeproj), clean the build folder, then rebuild.

See the react-native README for troubleshooting and development tasks.

Next Steps