Management API Reference

Ecosystem wallet

Create a React Native App

To make these instructions concrete, we have created a sample ecosystem wallet called Rapidfire ID. To interact with it, you can find its SDK in the NPM package directory: @rapidfire/id.

You can check out the GitHub repository for Rapidfire Wallet to learn how to create your own wallet.

This guide will walk you through adding support for any ecosystem wallet into a React Native app by integrating the Mobile Wallet Protocol Client.

If you need a template or scaffold to start with, you can check out the Ecosystem Wallet Expo Example.

Prerequisites#

Install peer dependencies#

The Mobile Wallet Protocol Client library requires the Expo WebBrowser and Async Storage packages to be installed. Follow the instructions on the respective pages for any additional setup.

[npm]
[yarn]

_10
npm i expo expo-web-browser @react-native-async-storage/async-storage

Polyfills#

Mobile Wallet Protocol Client requires crypto.randomUUID, crypto.getRandomValues, and URL to be polyfilled globally since they are not available in the React Native environment.

Below is an example of how to polyfill these functions in your app using the expo-crypto and expo-standard-web-crypto packages.

[npm]
[yarn]

_10
npm i expo-crypto expo-standard-web-crypto react-native-url-polyfill

[polyfills.js]
[App.tsx]

_10
import "react-native-url-polyfill/auto";
_10
import { polyfillWebCrypto } from "expo-standard-web-crypto";
_10
import { randomUUID } from "expo-crypto";
_10
_10
polyfillWebCrypto();
_10
crypto.randomUUID = randomUUID;

Setup#

Install Mobile Wallet Protocol Client#

Add the latest version of Mobile Wallet Protocol Client to your project.

[npm]
[yarn]

_10
npm i @mobile-wallet-protocol/client@latest

Usage#

Mobile Wallet Protocol Client provides 2 interfaces for mobile app to interact with the Smart Wallet, an EIP-1193 compliant provider interface and a wagmi connector.

If your app is using wallet aggregator, go straight to Option 2: Wagmi Connector for 1-line integration. :)

Option 1: EIP-1193 Provider#

Create a new EIP1193Provider instance, which is EIP-1193 compliant.

[App.tsx]

_27
import { EIP1193Provider } from "@mobile-wallet-protocol/client";
_27
_27
// Step 1. Initialize provider with your dapp's metadata and target wallet
_27
const metadata = {
_27
name: "My App Name",
_27
customScheme: "myapp://", // only custom scheme (e.g. `myapp://`) is supported in v1.0.0
_27
chainIds: [8453],
_27
logoUrl: "https://example.com/logo.png",
_27
};
_27
const provider = new EIP1193Provider({
_27
metadata,
_27
wallet: {
_27
type: 'web',
_27
name: "Rapid fire wallet",
_27
scheme: 'https://id.sample.openfort.xyz',
_27
iconUrl: 'https://purple-magnificent-bat-958.mypinata.cloud/ipfs/QmfQrh2BiCzugFauYF9Weu9SFddsVh9qV82uw43cxH8UDV',
_27
},
_27
});
_27
_27
// ...
_27
_27
// 2. Use the provider
_27
const addresses = await provider.request({ method: "eth_requestAccounts" });
_27
const signedData = await provider.request({
_27
method: "personal_sign",
_27
params: ["0x48656c6c6f20776f726c6421", addresses[0]],
_27
});

Option 2: Wagmi Connector#

Add the latest verion of Mobile Wallet Protocol wagmi-connectors to your project.

[npm]
[yarn]

_10
npm i @mobile-wallet-protocol/wagmi-connectors@latest

Simply import the createConnectorFromWallet function and pass in the wallet you want to use to wagmi config.

[config.ts]

_29
import {
_29
createConnectorFromWallet,
_29
Wallets,
_29
} from "@mobile-wallet-protocol/wagmi-connectors";
_29
_29
const metadata = {
_29
name: "My App Name",
_29
customScheme: "myapp://", // only custom scheme (e.g. `myapp://`) is supported in v1.0.0
_29
chainIds: [8453],
_29
logoUrl: "https://example.com/logo.png",
_29
};
_29
_29
export const config = createConfig({
_29
chains: [base],
_29
connectors: [
_29
createConnectorFromWallet({
_29
metadata,
_29
wallet: {
_29
type: 'web',
_29
name: "Rapid fire wallet",
_29
scheme: 'https://id.sample.openfort.xyz',
_29
iconUrl: 'https://purple-magnificent-bat-958.mypinata.cloud/ipfs/QmfQrh2BiCzugFauYF9Weu9SFddsVh9qV82uw43cxH8UDV',
_29
},
_29
}),
_29
],
_29
transports: {
_29
[base.id]: http(),
_29
},
_29
});

Then you can use wagmi's react interface to interact with the Smart Wallet.

[App.tsx]

_14
import { useConnect } from "wagmi";
_14
_14
// ...
_14
_14
const { connect, connectors } = useConnect();
_14
_14
return (
_14
<Button
_14
title={"Connect"}
_14
onPress={() => {
_14
connect({ connector: connectors[0] });
_14
}}
_14
/>
_14
);

Gas Sponsorship#

If you want to sponsor transactions, you need to add #policy=POLICY_ID to the wallet scheme.


_10
#policy=POLICY_ID

For example:

[config.ts]

_29
import {
_29
createConnectorFromWallet,
_29
Wallets,
_29
} from "@mobile-wallet-protocol/wagmi-connectors";
_29
_29
const metadata = {
_29
name: "My App Name",
_29
customScheme: "myapp://", // only custom scheme (e.g. `myapp://`) is supported in v1.0.0
_29
chainIds: [8453],
_29
logoUrl: "https://example.com/logo.png",
_29
};
_29
_29
export const config = createConfig({
_29
chains: [base],
_29
connectors: [
_29
createConnectorFromWallet({
_29
metadata,
_29
wallet: {
_29
type: 'web',
_29
name: "Rapid fire wallet",
_29
scheme: 'https://id.sample.openfort.xyz#policy=pol_a909d815-9b6c-40b2-9f6c-e93505281137',
_29
iconUrl: 'https://purple-magnificent-bat-958.mypinata.cloud/ipfs/QmfQrh2BiCzugFauYF9Weu9SFddsVh9qV82uw43cxH8UDV',
_29
},
_29
}),
_29
],
_29
transports: {
_29
[base.id]: http(),
_29
},
_29
});