Mobile apps are an integral part of modern life, and therefore integrating XION into mobile applications is a crucial step toward mass adoption. This guide will walk you through creating a React Native app using and the , based on the .
Prerequisites
Before you begin, ensure you have the following installed:
Android Emulator or iOS Simulator (or a physical device for testing)
Project Setup
Create a New Expo Project
Start by creating a new Expo project using the default template. This template is ideal for multi-screen apps.
Note: Ensure that the package and bundleIdentifier values are unique to your app. These must be distinct and not shared with other apps to successfully submit your application to the Google Play Store or Apple App Store.
Update the Main Tab (index.tsx)
Replace the contents of the app/(tabs)/index.tsx file with the following code to integrate Abstraxion authentication and transaction signing:
The new file now imports useAbstraxionAccount and useAbstraxionSigningClient from @burnt-labs/abstraxion-react-native, enabling authentication and transaction signing functionalities.
State Management with useState
Introduces state variables (signArbResponse, txHash, loadingInstantiate) to manage transaction status and responses.
New Authentication Logic
Includes authentication management (login, logout, isConnected, isConnecting) using useAbstraxionAccount().
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:
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 XION blockchain, 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 XION 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: