The Civic Auth Web3 API for React Native is currently in early access and
subject to change.
Overview
For apps requiring embedded wallet functionality with blockchain interactions. This approach includes everything from Authentication Only plus embedded Solana wallet creation and blockchain operations. What you get:- Everything from Authentication Only
- Embedded Solana wallet creation
- Transaction signing and sending
- Balance checking and message signing
- Non-custodial wallet management
Prerequisites
1. Complete Installation
Before starting, complete the Installation & Setup guide.2. Enable Web3 Wallets in Civic Dashboard
Critical Step: You must enable embedded wallets for your application in the Civic Auth dashboard:- Go to Civic Auth Dashboard
- Select your application
- Navigate to Settings or Features section
- Enable “Embedded Wallets” or “Web3 Wallets” feature
- Save your changes
3. Register Your App Domain/Scheme
Critical Step: Register your mobile app scheme with Civic Auth:- In the Civic Auth dashboard, go to your app settings
- Find the “Allowed Origins” or “Redirect URIs” section
- Add your mobile app scheme (e.g.,
myapp://oryourapp://) - Make sure it matches exactly with your app configuration
- If your app scheme is
myapp://, register:myapp:// - If your app scheme is
com.yourcompany.yourapp://, register:com.yourcompany.yourapp://
Your domain registration must match exactly with the scheme configured in your app’s
app.json or app.config.js file.Getting Started
After completing the prerequisites above, you can create a Web3 wallet for authenticated users using theuseWeb3Client hook. Embedded wallets are generated on behalf of users through our non-custodial wallet partner—neither Civic nor your app has access to the private keys.
Only embedded wallets are supported (no self-custodial wallet connections yet)
Installation
Install the SDK and its peer dependencies:- npm
- yarn
- pnpm
bash npm install @civic/react-native-auth-web3 @solana/web3.js Native Setup
Android Configuration
Add the following to yourandroid/app/build.gradle:
iOS Configuration
Requirements:- iOS 14.0 or higher
- Xcode 14.0 or higher
- Swift 5.0 or higher
This creates the native iOS project files needed for the next steps.
- Navigate to the Info tab of your app target settings in Xcode
- In the URL Types section, click the + button to add a new URL
- Enter the following values:
- Identifier:
metakeep - URL Schemes:
$(PRODUCT_BUNDLE_IDENTIFIER)
- Identifier:
ios/<YourAppName>/AppDelegate.swift file:
ios/Podfile:
If you encounter a “no such module ‘MetaKeep’” error, this step resolves it by adding the MetaKeep SDK to your iOS project dependencies.
application(_:open:options:) method in your ios/<YourAppName>/AppDelegate.swift file:
How Wallet Creation Works
After authenticating with Civic Auth, the SDK can create a non-custodial embedded wallet for the user. The creation process requires an ID token - a JWT received from Civic Auth after successful authentication. This token proves the user’s identity and links the wallet to their Civic account. Without a valid ID token, wallet creation will fail. This ensures only authenticated users can create wallets, with each wallet uniquely tied to a specific user account.Quick Start
The useWeb3Client Hook
TheuseWeb3Client hook returns a Web3Client object for interacting with blockchain networks. The client manages both wallet creation and transaction operations.
Web3Client Interface
SolanaWeb3Client Methods
Thesolana property provides access to Solana-specific operations:
Using the Wallet
Sending Transactions
You have two options for sending transactions:Option 1: Simple Transfer (Recommended)
UsesendTransaction for quick SOL transfers. It handles transaction creation, signing, and broadcasting:
Option 2: Custom Transactions
UsesignTransaction for complex transactions with custom instructions:
Checking Balance
Signing Messages
Complete Example
Here’s a complete authentication provider with Expo Auth Session and Web3 wallet creation:Troubleshooting
Common Domain Registration Issues
If wallet creation fails, check these common domain registration problems:❌ Domain Mismatch
Problem: Your registered domain doesn’t match your app scheme exactly. Example:- App scheme:
myapp:// - Registered domain:
myapp(missing://) - Result: Wallet creation fails
://
❌ Missing Wallet Feature
Problem: Embedded wallets not enabled in Civic dashboard. Symptoms:- Authentication works fine
createWallets()fails or returns null- Console errors about wallet features
❌ Incorrect Redirect URI
Problem: Using hardcoded redirect URI instead ofmakeRedirectUri()
Example:
Verifying Your Setup
To verify your domain registration is correct:- Check your
app.json/app.config.jsscheme matches registered domain - Test authentication first (should work without wallets)
- Only then test wallet creation
- Check browser developer tools for any CORS or domain errors
Example Repository
For a complete working example of Civic Auth with embedded wallets in a React Native application, check out our example repository: [https://github.com/civicteam/civic-auth-examples/tree/main/packages/mobile/react-native-expo]Crypto Polyfill
The SDK automatically includes a crypto polyfill using expo-crypto to provide thegetRandomValues function required by Solana’s PublicKey object. This polyfill ensures cryptographic operations work correctly in React Native environments where the Web Crypto API is not natively available.
The polyfill is applied automatically when you import the SDK, so no additional configuration is needed.
