bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 54쪽 중 13쪽
Address) {
const response = await signArb?.(
client.granteeAddress,
"abstraxion challenge"
);
if (response) setSignArbResponse(response);
}
}
function handleLogout() {
logout();
setSignArbResponse("");
setTxHash("");
}
return (
<View style={styles.container}>
<Text style={styles.title}>Abstraxion React-Native Demo</Text>
{isConnected ? (
<>
<TouchableOpacity
onPress={handleInstantiate}
style={styles.button}
disabled={loadingInstantiate}
>
<Text style={styles.buttonText}>
{loadingInstantiate ? "Loading..." : "Sample instantiate"}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={handleSign} style={styles.button}>
<Text style={styles.buttonText}>Sign Arb</Text>
</TouchableOpacity>
</>
) : null}
{isConnected ? (
<TouchableOpacity onPress={handleLogout} style={styles.button}>
<Text style={styles.buttonText}>Logout</Text>
</TouchableOpacity>
) : (
<TouchableOpacity
onPress={login}
style={[styles.button, isConnecting && styles.disabledButton]}
disabled={isConnecting}
>
<Text style={styles.buttonText}>
{isConnecting ? "Connecting..." : "Login"}
</Text>
</TouchableOpacity>
)}
{signArbResponse || txHash ? (
<View style={styles.card}>
{signArbResponse ? (
<Text style={styles.responseText}>{signArbResponse}</Text>
) : null}
{txHash ? <Text style={styles.responseText}>{txHash}</Text> : null}
</View>
) : null}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#f0f0f0",
alignItems: "center",
justifyContent: "center",
padding: 20,
},
title: {
fontSize: 24,
fontWeight: "bold",
marginBottom: 20,
color: "#333",
},
button: {
marginVertical: 10,
padding: 15,
borderRadius: 5,
backgroundColor: "#2196F3",
width: "80%",
alignItems: "center",
},
buttonText: {
color: "#fff",
fontSize: 16,
},
card: {
backgroundColor: "#fff",
padding: 15,
borderRadius: 10,
marginTop: 20,
width: "90%",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.2,
shadowRadius: 4,
elevation: 5,
},
responseText: {
color: "#000",
marginTop: 10,
fontSize: 16,
},
disabledButton: {
backgroundColor: "#B0BEC5",
},
});
```
Here are the key changes in the updated file:
1. **Integration with Abstraxion** package
* The new file now imports `useAbstraxionAccount` and `useAbstraxionSigningClient` from `@burnt-labs/abstraxion-react-native`, enabling authentication and transaction signing functionalities.
2. **State Management with `useState`**
* Introduces state variables (`signArbResponse`, `txHash`, `loadingInstantiate`) to manage transaction status and responses.
3. **New Authentication Logic**
* Includes authentication management (`login`, `logout`, `isConnected`, `isConnecting`) using `useAbstraxionAccount()`.
4. **Transaction Signing & Contract Instantiation**
* Adds a function (`handleInstantiate`) to instantiate a smart contract using `MsgInstantiateContract`.
### Remove explore tab
We'll not be using the Explore tab and so let's go ahead and remove it from the project. Delete the following file "**app/(tabs)/explore.tsx**".
### Update the Layout (`_layout.tsx`)
Replace the contents of `app/_layout.tsx` with the following code to set up the Abstraxion provider:
```typescript
import "react-native-reanimated";
import "react-native-get-random-values";
import * as SplashScreen from "expo-splash-screen";
import { useEffect } from "react";
import {
DarkTheme,
DefaultTheme,
ThemeProvider,
} from "@react-navigation/native";
import { useFonts } from "expo-font";
import { Stack } from "expo-router";
import { StatusBar } from "expo-status-bar";
import { AbstraxionProvider } from "@burnt-labs/abstraxion-react-native";
import { useColorScheme } from "@/hooks/useColorScheme";
import { Buffer } from "buffer";
import crypto from "react-native-quick-crypto";
global.crypto = crypto;
global.Buffer = Buffer;
SplashScreen.preventAutoHideAsync();
const treasuryConfig = {
treasury: "xion1r0tt64mdld2svywzeaf4pa7ezsg6agkyajk48ea398njywdl28rs3jhvry",
gasPrice: "0.001uxion",
rpcUrl: "https://rpc.xion-testnet-2.burnt.com:443",
restUrl: "https://api.xion-testnet-2.burnt.com:443",
callbackUrl: "abstraxion-expo-demo://",
};
export default function RootLayout() {
const colorScheme = useColorScheme();
const [loaded] = useFonts({
SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
});
useEffect(() => {
if (loaded) {
SplashScreen.hideAsync();
}
}, [loaded]);
if (!loaded) {
return null;
}
return (
<AbstraxionProvider config={treasuryConfig}>
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
<Stack>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen name="+not-found" />
</Stack>
<StatusBar style="auto" />
</ThemeProvider>
</AbstraxionProvider>
);
}
```
Here’s a breakdown of the key modifications:
#### 1. **New Imports**
* **`import "react-native-get-random-values";`**
* This import ensures that cryptographic random values can be properly generated.
* **`import { AbstraxionProvider } from "@burnt-labs/abstraxion-react-native";`**
* This adds support for the **Abstraxion** library.
* **`import { Buffer } from "buffer";` and `import crypto from "react-native-quick-crypto";`**
* Commonly used for handling binary data.
#### 2. **Global Object Modifications**
* **`global.crypto = crypto;`**
* Assigns `react-native-quick-crypto` as the global crypto library, ensuring cryptographic functions work correctly.
* **`global.Buffer = Buffer;`**
* Makes the `Buffer` object globally available.
#### 3. **New `treasuryConfig` Object**
* Contains configuration for interacting with the **Verona network**, including:
* **Treasury address**: `"xion1r0tt64mdld2svywzeaf4pa7ezsg6agkyajk48ea398njywdl28rs3jhvry"` that allows for gasless transaction. You would update this contract with your own treasity address when building your own custom app.
* **RPC & REST URLs**: Connecting to **Verona** network
* **Callback URL**: `"abstraxion-expo-demo://"` for handling deep linking.
#### 4. **Introduction of `AbstraxionProvider`**
* Wraps the application inside `<AbstraxionProvider config={treasuryConfig}>`, providing the app with **Abstraxion** functionalities.
### Add Metro Configuration
Create a `metro.config.js` file in the root of your project to configure Metro:
```javascript
const { getDefaultConfig } = require("expo/metro-config");
const {
withLibsodiumResolver,
} = require("@burnt-labs/abstraxion-react-native/metro.libsodium");
const config = getDefaultConfig(__dirname);
module.exports = withLibsodiumResolver(config);
```
## Run the Project
To build and run the app on your emulator or device, use the following commands for your respective environment:
**For Android:**
```bash
npx expo run:android
```
**For iOS:**
```bash
npx expo run:ios
```
## Video Demo
For a visual walkthrough of the app, check out this video demo
{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB5Z5ijJgMx0GJO3l1Il9%2Fuploads%2F7t2NOuNYZaDnd1CaUcBt%2FAbstraxtion%20React%20Native%20Demo.mp4?alt=media&token=9a54fb1c-cfc2-467b-bbfd-23e04843f926>" %}
# Create Mobile App and Integrate Meta Account Authentication
This guide walks you through how to integrate Meta Account authentication into your mobile app using the `@burnt-labs/abstraxion-react-native` package. With Meta Accounts, users can easily sign in using familiar login methods such as email or social accounts, eliminating the need for wallets or seed phrases. This simplifies the onboarding experience and lowers the barrier for mainstream adoption by providing a secure, traditional style authentication flow within a blockchain application.
## Prerequisites
Before getting started, ensure you have the following installed:
* [Node.js](https://nodejs.org/en/) (v24 or later)
* A code editor like [VS Code](https://code.visualstudio.com/)
## What Are Meta Accounts?
Meta Accounts are smart contract accounts created and managed by Verona’s Abstraxion system. They abstract away traditional blockchain complexity and provide:
* **An oAuth2 style login mechanism** (no wallet required) that allows for login via email, social accounts, passkeys and crypto wallets
* **Instant execution of pre-approved smart contract calls**
* **Gasless transactions which allows for easy user onboarding**
## Create a New Expo Project
In your terminal, run the following commands which will create an Expo app with minimum required npm dependencies without configuring navigation due to the use of the `blank` template:
```bash
npx create-expo-app my-xion-app --template blank-typescript
cd my-xion-app
```
### Install Required Dependencies
Install the Abstraxion React Native package and storage utility:
```sh
npm install @burnt-labs/abstraxion-react-native @react-native-async-storage/async-storage@2.1.2 react-native-get-random-values react-native-libsodium react-native-quick-crypto expo-dev-client
```
## Set Up Environment Variables
Environment variables are key-value pairs configured outside your source code that allow your app to behave differently depending on the environment. The Expo CLI will automatically load environment variables with an `EXPO_PUBLIC_` prefix from `.env` files for use within your code.
To interact with your deployed contracts, you’ll set a few environment variables:
Create a `.env.local` file in the root of your project and add the following where we've added an example contract with a treasury contract that's configured to work along with it:
```env
EXPO_PUBLIC_USER_MAP_CONTRACT_ADDRESS="xion1xlsdw7en2a45v9z7stmfrml3f88zj6lrxcq5uk7vv4xy4wyhjdqqlgwqa8"
EXPO_PUBLIC_TREASURY_CONTRACT_ADDRESS="xion1hcuf8dv4n2h6gffez3e0y70gjm20g72mtmcl3qf7t4q0laz5ef0shfm50z"
EXPO_PUBLIC_RPC_ENDPOINT="https://rpc.xion-testnet-2.burnt.com:443"
EXPO_PUBLIC_REST_ENDPOINT="https://api.xion-testnet-2.burnt.com"
```
* **EXPO\_PUBLIC\_CONTRACT\_ADDRESS -** The address of the smart contract your app will interact with.
* **EXPO\_PUBLIC\_TREASURY\_CONTRACT\_ADDRESS -** The treasury contract associated with the above contract. It enables gasless transactions using fee grants and handles authorization permissions, allowing your app to execute transactions on behalf of the Meta Account holder—delivering a seamless user experience.
* **EXPO\_PUBLIC\_RPC\_ENDPOINT -** The RPC endpoint used to communicate with the Verona network.
* **EXPO\_PUBLIC\_REST\_ENDPOINT -** The REST endpoint for querying chain state via HTTP.
You can access these values in your code using `process.env.`. For example:
```ts
const contractAddress = process.env.EXPO_PUBLIC_CONTRACT_ADDRESS;
```
## Set Up "AbstraxionProvider"
The `AbstraxionProvider` gives your app access to authentication and wallet state globally.
### Update "app.json"
There are some important items here that have to be set for your app to run on either android and ios. Expo uses a `scheme` to know which app to redirect back to and this must be unique to your app. Also for **Android** a `package` name must be set and for **iOS** a `bundleIdentifier` must be set.
Update your `app.json` file with the following;
```json
{
"expo": {
"name": "my-xion-app",
"slug": "my-xion-app",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"newArchEnabled": true,
"scheme": "abstraxion-expo-demo",
"splash": {
"image": "./assets/splash-icon.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.anonymous.myxionapp"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"edgeToEdgeEnabled": true,
"package": "com.anonymous.myxionapp"
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
```
### Update "App.tsx"
```tsx
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import { AbstraxionProvider } from "@burnt-labs/abstraxion-react-native";
const treasuryConfig = {
treasury: EXPO_PUBLIC_TREASURY_CONTRACT_ADDRESS,
gasPrice: "0.001uxion",
rpcUrl: EXPO_PUBLIC_RPC_ENDPOINT,
restUrl: EXPO_PUBLIC_REST_ENDPOINT,
callbackUrl: "abstraxion-expo-demo://", // This comes from app.json and should be unique to your app
};
export default function App() {
return (
<AbstraxionProvider config={treasuryConfig}>
<View style={styles.container}>
<Text>Open up App.tsx to start working on your app!</Text>
<StatusBar style="auto" />
</View>
</AbstraxionProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
```
This wraps your entire app and ensures all child components can access authentication state and methods.
### Authentication Flows
Once wrapped in the provider, you can use the `useAbstraxion()` hook to access login methods, wallet state, and logout. Let's implement login and logout buttons to see authentication in action. Let's update `App.tsx` with the following:
```tsx
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import { useAbstraxionAccount, useAbstraxionSigningClient, AbstraxionProvider } from '@burnt-labs/abstraxion-react-native';
import { useState } from 'react';
const treasuryConfig = {
treasury: process.env.EXPO_PUBLIC_TREASURY_CONTRACT_ADDRESS,
gasPrice: "0.001uxion",
rpcUrl: process.env.EXPO_PUBLIC_RPC_ENDPOINT,
restUrl: process.env.EXPO_PUBLIC_REST_ENDPOINT,
callbackUrl: "abstraxion-expo-demo://", // This comes from app.json and should be unique to your app
};
function AppContent() {
const account = useAbstraxionAccount();
const { client: signingClient } = useAbstraxionSigningClient();
const [isConnecting, setIsConnecting] = useState(false);
const handleLogin = async () => {
try {
setIsConnecting(true);
await signingClient?.signIn();
} catch (error) {
console.error('Login error:', error);
} finally {
setIsConnecting(false);
}
};
const handleLogout = async () => {
try {
await signingClient?.signOut();
} catch (error) {
console.error('Logout error:', error);
}
};
return (
<View style={styles.container}>
<Text style={styles.title}>Verona Abstraxion Demo</Text>
{account ? (
<View style={styles.userInfo}>
<Text style={styles.welcomeText}>Welcome!</Text>
<Text style={styles.addressText}>Address: {account.publicKey}</Text>
<TouchableOpacity
style={styles.button}
onPress={handleLogout}
disabled={isConnecting}
>
<Text style={styles.buttonText}>
{isConnecting ? 'Logging out...' : 'Logout'}
</Text>
</TouchableOpacity>
</View>
) : (
<TouchableOpacity
style={styles.button}
onPress={handleLogin}
disabled={isConnecting}
>
<Text style={styles.buttonText}>
{isConnecting ? 'Connecting...' : 'Login with Verona'}
</Text>
</TouchableOpacity>
)}
<StatusBar style="auto" />
</View>
);
}
export default function App() {
return (
<AbstraxionProvider config={treasuryConfig}>
<AppContent />
</AbstraxionProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
padding: 20,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 30,
},
userInfo: {
alignItems: 'center',
gap: 10,
},
welcomeText: {
fontSize: 20,
fontWeight: '600',
marginBottom: 10,
},
addressText: {
fontSize: 14,
color: '#666',
marginBottom: 20,
},
button: {
backgroundColor: '#007AFF',
paddingHorizontal: 20,
paddingVertical: 12,
borderRadius: 8,
minWidth: 200,
alignItems: 'center',
},
buttonText: {
color: '#fff',
fontSize: 16,
fontWeight: '600',
},
});
```
Here's what has been added:
**Login Functionality**
* A **“Login with Verona”** button appears when the user is not logged in.
* Utilizes the `useAbstraxionSigningClient` hook to handle authentication.
* Displays a loading state while connecting.
**Logout Functionality**
* A **“Logout”** button appears when the user is logged in.
* Uses the `disconnect` method from the signing client to log out.
* Displays a loading state while logging out.
**User Information Display**
* The user’s address is shown once logged in.
* Clean, modern UI with appropriate styling.
**Error Handling**
* Proper error catching implemented for both login and logout operations.
* Loading states prevent repeated clicks and improve UX.
***
#### How to Test It
1. Run your app.
{% tabs %}
{% tab title="For Android" %}
`npx expo run:android`
{% endtab %}
{% tab title="For iOS" %}
`npx expo run:ios`
{% endtab %}
{% endtabs %}
1. Click the **“Login with Verona”** button.
2. Complete the Verona Abstraxion authentication flow.
3. Upon success, your address should appear along with a **“Logout”** button.
4. Click **“Logout”** to disconnect the session.
## What’s Next?
Now that your app is authenticated with Meta Accounts, you're ready to start interacting with the blockchain.
Depending on your goals, here are two paths you can take next:
### Launch a Mobile app in 5 Minutes
If you're looking to get something up and running **quickly**, follow our streamlined quick-start guide: [**Launch a Mobile dApp in 5 Minutes**](/en/build-on-verona/computation/quick-start/zero-to-dapp-in-5-minutes/react-native-mobile-dapp-in-5-minutes)**.**
\
This guide walks you through:
* Using our one-click launcher to deploy a contract and frontend
* Setting up a mobile app using a prebuilt template
* Authenticating users and saving their data to the blockchain
It’s the fastest way to see the full app lifecycle in action.
### Deep Dive: How the Mobile app is built
If you want to understand **how the mobile app works under the hood**, explore this step-by-step tutorial: [**Building a React Native Mobile App with Abstraxion**](/en/build-on-verona/accounts/mobile-app/building-a-react-native-mobile-app-with-abstraxion)**.**
\
This guide breaks down:
* Smart contract integration using the `Abstraxion` package
* Transaction execution with Meta Accounts
* Querying and updating on-chain data
* Structuring your app for production use
It's ideal if you're building custom flows, want to extend contract functionality, or are preparing for a real-world deployment.
# Mobile Development – Common Errors & Fixes
When developing mobile applications for Android or iOS, encountering build errors is a regular part of the process. These errors can stem from SDK misconfigurations, dependency issues, or quirks in cross-platform libraries like React Native. Below is a list of common issues developers face, along with tested solutions.
### 1. Broken or Missing Build Tools (Android)
**Error:**
```
Build-tool 35.0.0 is missing AAPT at /.../build-tools/35.0.0/aapt
FAILURE: Build failed with an exception.
> Installed Build Tools revision 35.0.0 is corrupted. Remove and install again using the SDK Manager.
```
**Symptoms:**
* Gradle build fails almost immediately.
* Compilation of Java sources (`:app:compileDebugJavaWithJavac`) cannot proceed.
* Error points to a corrupted or incomplete installation of Build Tools.
**Solution:**
1. Open **Android Studio**.
2. Go to **SDK Manager → SDK Tools**.
3. Uncheck and re-check **Android SDK Build-Tools 35.0.0**, then click **Apply** to reinstall.
4. Alternatively, run:
```bash
sdkmanager --uninstall "build-tools;35.0.0"
sdkmanager "build-tools;35.0.0"
```
### 2. `expo run:android` Fails – Emulator Not Detected
**Error:**
```
adb.exe: device 'emulator-5554' not found
CommandError: Failed to get properties for device (emulator-5554)
```
**Likely Cause:**
* The Android Debug Bridge (ADB) cannot find a running emulator.
* Emulator may not be initialized or started properly.
**Solution:**
1. Start Android Studio.
2. Go to **Tools → Device Manager**, then **launch a virtual device**.
3. Verify the emulator is listed using:
```bash
adb devices
```
You s프로젝트로 돌아가기