Portal
The Portal
class that houses three main sub-classes
api
makes requests to the Portal apimpc
facilitates the generation, backup, and recovery of MPC walletsprovider
the core Portal provider (EIP-1139 compliant)
Instantiation
When instantiating the Portal
class, you must provide a PortalOptions
object. This object is used to initialize all of the sub-classes (and their sub-classes).
Example instantiation
import { BackupMethods, Portal } from '@portal-hq/react-native'
const portal = new Portal({
apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
folder: 'YOUR_PREFERRED_FOLDER_NAME',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
})
PortalOptions
The PortalOptions
object is where you configure your instance of Portal
. It contains a set of required properties and a set of optional properties.
Required properties
apiKey
string a valid Portal Client API Key created via the Portal REST APIbackupConfig
object
method
BackupMethods the supported backup method you'd like to use for storing backup MPC
- You can use the exported enum
BackupMethods
to set this value which contains the following supported backup methods:
androidClientId
string (only used for GoogleDrive
) the Android Client ID (get one)iosClientId
string (only used for GoogleDrive
) the iOS Client ID (get one)folder
string the folder you'd like to store backup shares in (this folder will be created in the root of your users' Google Drive or iCloud)
chainId
number the ID of the current Ethereum chain you'd like to perform actions on
- You can update this property on your
Portal
instance later – if your app requires this – by setting portal.chainId
property
infuraId
string your Infura API Key – this will be used for making read requests in the providerisSimulator
boolean whether or not you're currently running the app in a simulator (this is required to ensure that keychain storage is configured appropriately for the current device)
Optional properties
autoApprove
boolean (default: false
) whether you'd like the provider to auto-approve transactionsmpcEnabled
boolean (default: true
) whether or not to use MPCrpcConfig
string or RpcConfig the base url (including your API key) you'd like us to use for Gateway requests (reading from and writing to chain) Note: this will be required in the future
RpcConfig
– if you don't want to use the same url for all requests, you can instead provide a chain-level config for all Gateway RPC calls this can be passed in as an object with key/value pairs where the key
is the chainId
as a number and the value is the base url you'd like to use when performing actions on this chainId
api
The api
property contains an instance of the PortalApi
class, which has a number of helper methods to facilitate the retrieval of relevant application data from the Portal REST API.
Methods
getEnabledDapps
Fetches a list of allowed dApps based on your dApp settings in the Portal web app.
Example usage
const portal = new Portal({
apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
})
const dapps = await portal.api.getEnabledDapps()
getNetworks
Fetches a list of supported networks based on your dApp settings in the Portal web app.
Example usage
const portal = new Portal({
apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
})
const networks = await portal.api.getNetworks()
mpc
The mpc
property contains an instance of the PortalMpc
class, which has a number of helper methods to facilitate the management of Portal MPC wallets.
Methods
generate
Performs the MPC generate process to create an MPC wallet and its signing shares
Example usage
const portal = new Portal({
apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
})
const createWallet = async () => {
await portal.mpc.generate()
}
backup
Performs the MPC backup process to create the backup shares for the generated MPC wallet.
Example usage
const portal = new Portal({
apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
})
const backupWallet = async () => {
await portal.mpc.backup()
}
recover
Performs the MPC recovery process to generate new signing shares for the MPC wallet.
Example usage
const portal = new Portal({
apiKey: 'YOUR_PORTAL_CLIENT_API_KEY',
backupConfig: {
method: BackupMethods.GoogleDrive,
androidClientId: 'YOUR_GOOGLE_DRIVE_CLIENT_ID',
iosClientId: 'YOUR_GOOGLE_DRICE_CLIENT_ID',
},
chainId: 1,
infuraId: 'YOUR_INFURA_ID',
isSimulator: DeviceInfo.isEmulator(),
rpcConfig: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY',
})
const recoverWallet = async () => {
await portal.mpc.recover()
}
provider
The provider
property contains an EIP-1139 compliant provider.
Making requests through the provider
In order to perform basic web3 operations, such as eth_accounts
and eth_sendTransaction
, you can use the provider's request
method.
This method conforms to EIP-1139.
Example usage
const transaction = {
data: '',
to: toAddress,
value: BigNumber.from('1').toHexString(),
gas: '0x6000',
from: portal.address,
}
const txHash = await portal.provider.request({
method: 'eth_sendTransaction',
params: transaction,
})
For more information on how to use this provider natively within your React Native app, see the Provider Docs.