Skip to content

Wallet Configuration

Configure smart wallets to match your app’s requirements. Openfort React lets you:

  • Set recovery methods (automatic, password-based)
  • Adjust wallet creation options and chain preferences
  • Manage wallet state and embedded wallet lifecycle

Configuration

To configure Openfort in your React app, set up the OpenfortProvider with your publishable key and wallet configuration.

import { OpenfortProvider, RecoveryMethod } from '@openfort/react-native'
 
function App() {
  return (
    <OpenfortProvider
      // ... other configuration
      publishableKey="YOUR_OPENFORT_PUBLISHABLE_KEY"
 
      // Set the wallet configuration.
      walletConfig={{
        shieldPublishableKey: "YOUR_SHIELD_PUBLISHABLE_KEY",
        // If you want to use AUTOMATIC embedded wallet recovery, an encryption session is required.
        // getEncryptionSession: async () => {
        // fetch the encryption session from your backend
        // return "ENCRYPTION_SESSION"
        // }
      }}
    >
      <>
        {/* Add your wallet components here */}
      </>
    </OpenfortProvider>
  )
}

Using openfort wallets

To use Openfort wallets in your React app, you can utilize the useWallets hook. This hook provides methods to create, manage, and interact with wallets.

import { useWallets } from "@openfort/react-native"
 
function SampleComponent() {
  const {
    wallets, // List of the wallets of the user.
    activeWallet, // The currently active wallet in the application.
    setActiveWallet, // Set the active wallet for the application.
    createWallet, // Create a new wallet.
    error, // The error object if an error occurred, otherwise null.
    isError, // Indicates if the hook has encountered an error.
    isSuccess, // Indicates if the hook has successfully completed.
    isCreating,
    isConnecting,
    exportPrivateKey, // Export the private key of the active wallet.
  } = useWallets({
    throwOnError, // Whether to throw errors.
    onSuccess, // Callback function to execute on success.
    onError, // Callback function to execute on error.
    onSettled, // Callback function to execute when the operation is settled (either success or error).
  })
  // ...
}