React Native

Follow this guide to integrate Portal in your app.
Portal provides MPC wallets and dApp connections for exchanges and their users. To integrate Portal, an exchange adds a client library to their mobile app and a few server API endpoints.
The Portal library connects your mobile app and server with the web3 ecosystem.

Video Walkthrough

One of our founders, Rami, walks you through how to get started with our React Native SDK in two parts.
Overview of the Portal React Native dependencies
Completing you first transaction with Portal

Basic setup

The basic Portal setup consists of three packages:
  • @portal-hq/core - The core Portal library
  • @portal-hq/keychain - An adapter for storing MPC signing shares on-device
  • @portal-hq/gdrive-storage - An adapter for storing MPC backup shares off-device
These pieces allow you to initialize Portal in your app.

Authentication

Follow this guide to gather all of the credentials you need to Authenticate to Portal.

Installation

yarn
npm
yarn add @portal-hq/core @portal-hq/keychain @portal-hq/gdrive-storage
npm install --save @portal-hq/core @portal-hq/keychain @portal-hq/gdrive-storage

Dependency linking

Because these packages have native module dependencies there is some additional linking required to make it work with your React Native project.
Explicitly install the native module packages in your project.
yarn
npm
yarn add react-native-keychain react-native-rsa-native
npm install --save react-native-keychain react-native-rsa-native

MPC

The core Portal library relies on a native module to support MPC behaviors. In order to enable this functionality, you must properly link Portal's MPC client to your React Native project.
Android
iOS
app/build.gradle
dependencies {
...
runtimeOnly files("../../node_modules/@portal-hq/core/android/libs/mpc.aar")
...
}
cd ios && pod install && cd ..
To learn more about how to use Portal MPC, see: @portal-hq/core

Initializing Portal

MyAppComponent.tsx
1
import { useEffect, useState } from 'react'
2
3
// Portal imports
4
import { BackupMethods, Portal, PortalContextProvider } from '@portal-hq/core'
5
import Keychain from '@portal-hq/keychain'
6
import Storage from '@portal-hq/gdrive-storage'
7
8
const MyAppComponent = () => {
9
// Store the Portal instance in the state
10
const [portal, setPortal] = useState<Portal>(null)
11
12
useEffect(() => {
13
if (!portal) {
14
// Initialize storage providers
15
const keychain = new Keychain()
16
const gDriveStorage = new Storage({
17
androidClientId: 'YOUR_ANDROID_CLIENT_ID',
18
iosClientId: 'YOUR_IOS_CLIENT_ID',
19
})
20
// Create a Portal instance
21
setPortal(
22
new Portal({
23
apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
24
backup: {
25
[BackupMethods.GoogleDrive]: gDriveStorage,
26
},
27
chainId: 1,
28
gatewayConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
29
isSimulator: true,
30
keychain,
31
}),
32
)
33
}
34
}, [portal])
35
36
return (
37
{/* Expose your Portal instance to your app */}
38
<PortalContextProvider value={portal as Portal}>
39
{/**
40
* Now all children rendered in this scope
41
* will have access to the `Portal` instance
42
* via the `usePortal` hook
43
*/}
44
</PortalContextProvider>
45
)
46
}
47
48
export default MyAppComponent
For more information on how to use the Portal class, see: @portal-hq/core

Next Steps

Now that you've initialized your Portal instance, you can generate a wallet!