Verona 백서

Verona

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 54쪽 중 12쪽

(+ type/token per `.env.example`); else RPC discovery. | | No | **`treasuryIndexer`** | **`{ url }`** when treasury indexer env is set. | If your **`SignerAuthentication`** type still lists **`aaApiUrl`** / **`smartAccountContract`**, populate them from the **same `chainId` preset** (not new values you invent)—equivalent to copying the block for that network from [**`demos/react/.env.example`**](https://github.com/burnt-labs/xion.js/blob/main/demos/react/.env.example) into config. ### Top-level `config` & environment variables **`chainId`** is required. **`normalizeAbstraxionConfig`** fills **`rpcUrl`**, **`restUrl`**, **`gasPrice`**, and **`feeGranter`** from **`@burnt-labs/constants`** when omitted for a known Verona **`chainId`**. **`aaApiUrl`** and **`smartAccountContract`** are **not** filled by that same helper in the public SDK today—treat them as **documented presets per network** (same values as the **`chainId` block** in [**`demos/react/.env.example`**](https://github.com/burnt-labs/xion.js/blob/main/demos/react/.env.example)): copy or merge them in app config. You override only for **custom** AA / wasm. | Required? | Variable | Maps to | | --------- | ---------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | | Yes | `NEXT_PUBLIC_CHAIN_ID` or `VITE_CHAIN_ID` | `config.chainId` — required network id; enables RPC/REST/gas/fee-granter **defaults** via **`normalizeAbstraxionConfig`** when those env vars are unset. | | No | `NEXT_PUBLIC_AA_API_URL` / `VITE_AA_API_URL` | `authentication.aaApiUrl` — **override**; demo reads from env. | | No | `NEXT_PUBLIC_CODE_ID` / `VITE_CODE_ID` | `authentication.smartAccountContract.codeId` — **override**; demo reads from env. | | No | `NEXT_PUBLIC_CHECKSUM` / `VITE_CHECKSUM` | `authentication.smartAccountContract.checksum` — **override**; demo reads from env. | | No | `NEXT_PUBLIC_ADDRESS_PREFIX` / `VITE_ADDRESS_PREFIX` | `authentication.smartAccountContract.addressPrefix` (demo → **`xion`** if unset) | | No | `NEXT_PUBLIC_RPC_URL` / `VITE_RPC_URL` | `config.rpcUrl` | | No | `NEXT_PUBLIC_REST_URL` / `VITE_REST_URL` | `config.restUrl` | | No | `NEXT_PUBLIC_GAS_PRICE` / `VITE_GAS_PRICE` | `config.gasPrice` | | No | `NEXT_PUBLIC_TREASURY_ADDRESS` / `VITE_TREASURY_ADDRESS` | `config.treasury` (gasless UX) | | No | `NEXT_PUBLIC_FEE_GRANTER_ADDRESS` / `VITE_FEE_GRANTER_ADDRESS` | `config.feeGranter` | | No | `NEXT_PUBLIC_INDEXER_URL` / `VITE_INDEXER_URL` | builds `authentication.indexer` (with **`INDEXER_TYPE`** / **`INDEXER_TOKEN`** as in `.env.example`) | | No | `NEXT_PUBLIC_TREASURY_INDEXER_URL` / `VITE_TREASURY_INDEXER_URL` | `authentication.treasuryIndexer.url` | | No | `NEXT_PUBLIC_TURNKEY_ORG_ID` / `VITE_TURNKEY_ORG_ID` | Turnkey demo wiring only | | No | `NEXT_PUBLIC_TURNKEY_API_BASE_URL` / `VITE_TURNKEY_API_BASE_URL` | Turnkey demo wiring only | **Next.js:** if a server layout reads **`process.env` at runtime**, use **`export const dynamic = "force-dynamic"`**. The **demo** reads AA / wasm from env; if **`CODE_ID`** / **`CHECKSUM`** are missing in the browser, it **logs an error**. Your app can instead **hardcode or merge** the `.env.example` preset for your **`chainId`** and omit those env vars. # Custom UI and Abstraxion loading states Hook-first Abstraxion auth — loading flags, login(), session lifecycle (live /auto demo) This guide is about **your own buttons, copy, and loading states**—using **`useAbstraxionAccount`** (and optionally **`useAbstraxionSigningClient`**) with **`login()`**, not the legacy **`<Abstraxion />`** modal / **`@burnt-labs/ui`** bundle. It goes deeper on **granular loading flags** and **redirect return** handling than the [Account abstraction tutorial](/en/build-on-verona/accounts/web-app/build-react-dapp-with-account-abstraxion) (which already uses the same hook-first connect pattern). It does **not** walk through choosing or comparing **`authentication.type`**; that belongs in the section hub. **Live reference:** [sdk-react.demos.burnt.com/auto](https://sdk-react.demos.burnt.com/auto) (hook-first connect; source in [`demos/react`](https://github.com/burnt-labs/xion.js/tree/main/demos/react)). **Prerequisite:** You have already wrapped the app with **`AbstraxionProvider`** and set **`authentication`** (for dashboard Meta Account login, **`auto`** is the usual default). See [Web App Development](/en/build-on-verona/accounts/web-app) for the mode glossary, env vars, and when to use **`signer`** or **embedded**—those topics are not repeated here. The **`login()`**, **`?granted=true`**, and flag patterns below apply to **dashboard-style** flows (`auto` / `popup` / `redirect`); for **`type: "signer"`**, start from [Abstraxion signer mode](/en/build-on-verona/accounts/web-app/abstraxion-signer-mode). Hook-level flags are **independent of whether you render a modal**: they describe session and navigation state from the SDK, not a specific widget. ## `useAbstraxionAccount` flags Destructure the hook and drive your layout from granular booleans (wording aligned with the demo tooltips): | Flag | Meaning | | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | | **`isInitializing`** | Brief period after mount before the provider knows real connection state (avoid flashing “logged out” too early). | | **`isConnecting`** | User initiated login; active connection attempt in progress. | | **`isConnected`** | Context resolved: user has an active session **or** you can treat as “ready to show app shell.” | | **`isDisconnected`** | User explicitly logged out; blocks auto re-connect until they start login again. | | **`isLoading`** | Aggregated busy state: initializing, connecting, or transitional work—use for disabling primary actions / showing a single spinner. | | **`isReturningFromAuth`** | User just came back from the auth app callback (e.g. redirect flow); optional dedicated “Finishing sign-in…” UI. | | **`isLoggingIn`** | Narrow window right after `login()` is invoked while the SDK starts the flow. | **Session lifecycle (simplified):** mount → **`isInitializing`** → restored session or disconnected → user taps connect → **`isLoggingIn`** / **`isConnecting`** → popup closes or redirect returns (**`isReturningFromAuth`**) → **`isConnected`** with `data.bech32Address`. Use **`isLoading`** when you want one gate for “disable submit / show full-page loader”; combine finer flags when you want different copy for “opening auth” vs “restoring session”. ## `login()` without the `<Abstraxion />` modal Call **`login()`** from `useAbstraxionAccount` to start authentication without importing the pre-built modal component. ```typescript const { data: account, login, logout, isConnecting, isLoading } = useAbstraxionAccount(); ``` You do **not** need a separate Abstraxion CSS bundle for hook-only UIs built with your own components. ## Optional: finishing login after redirect With **`auto`** on desktop, auth often runs in a **popup** and the parent page stays mounted. With **full-page redirect** (typical mobile leg of **`auto`**, or explicit **`redirect`**), the user may return to your URL with **`?granted=true`**. Call **`login()`** once to finalize session restoration (the demo illustrates this). Popup-heavy flows hit this path less often. ```typescript useEffect(() => { const searchParams = new URLSearchParams(window.location.search); if (searchParams.get("granted") === "true") { void login(); } }, [login]); ``` ## Example: minimal custom UI ```typescript import { useAbstraxionAccount, useAbstraxionSigningClient } from "@burnt-labs/abstraxion-react"; const btnClass = "w-full rounded-md border border-zinc-600 bg-zinc-900 px-4 py-2 text-white disabled:opacity-50"; export default function Page(): JSX.Element { const { data: account, login, logout, isLoading, isConnected, } = useAbstraxionAccount(); const { client } = useAbstraxionSigningClient(); if (isLoading && !isConnected) { return ( <main className="flex min-h-screen items-center justify-center p-4"> <p className="text-sm text-neutral-400">Preparing wallet session…</p> </main> ); } return ( <main className="m-auto flex min-h-screen max-w-xs flex-col items-center justify-center gap-4 p-4"> <h1 className="text-2xl font-bold text-white">ABSTRAXION</h1> {account?.bech32Address ? ( <> <p className="truncate text-xs text-neutral-400">{account.bech32Address}</p> {client ? <p className="text-xs text-green-400">Signing client ready</p> : null} <button type="button" className={btnClass} onClick={() => logout()}> LOGOUT </button> </> ) : ( <button type="button" className={btnClass} disabled={isLoading} onClick={() => void login()} > CONNECT </button> )} </main> ); } ``` ## Migrating from the legacy modal pattern 1. Remove **`<Abstraxion />`** if you still mount the old bundled modal. 2. Prefer **`login()`** (and **`logout()`**) with **native `<button>`** (or your design system) instead of Burnt UI primitives. 3. Replace a single “connecting” boolean with the **granular flags** above to avoid UI flicker and double-submits. ## Related * [Web App Development — modes hub](/en/build-on-verona/accounts/web-app) * [Account abstraction with gasless transactions (hook-first tutorial)](/en/build-on-verona/accounts/web-app/build-react-dapp-with-account-abstraxion) * [Abstraxion signer mode](/en/build-on-verona/accounts/web-app/abstraxion-signer-mode) # Mobile App Development Build native iOS and Android apps with blockchain functionalities with Dave, powered by Verona. {% hint style="success" %} Get a mobile app up and running fast:\ [**Build a React Native Mobile app 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 is designed to give developers instant look at a working app on Verona, without needing to write or compile code, set up a local dev environment, or build out a frontend. {% endhint %} Verona has developed Dave, the Premier Mobile Development Kit, enabling builders to meet users where they are. Mobile app development on Verona refers to the process of creating blockchain-based applications specifically optimized for mobile platforms (iOS and Android), using familiar tools like **React Native** and **Expo**, while leveraging Verona’s native features such as: * **Meta Accounts**: Smart contract accounts abstracted behind familiar authentication methods like email or social login. * **Treasury Contracts**: A powerful mechanism that lets your app sponsor transaction fees, enabling gasless usage for your users and enable requesting permissions from users to execute transactions on their behalf. * **Abstraxion SDKs**: Tools that make building with Verona as simple as possible, including packages tailored to mobile platforms. The goal is to meet billions of users where they are, without requiring end-users to understand the complexities of the blockchain. ## Abstraxion React Native Package The [`@burnt-labs/abstraxion-react-native`](https://www.npmjs.com/package/@burnt-labs/abstraxion-react-native) package is the core library for building mobile apps on Verona. It brings the full power of the Abstraxion Meta Account system and simplifies authentication, signing, and fee grants in a native mobile environment. #### Key Benefits: * **Optimized for React Native & Expo** – Seamlessly integrates with mobile projects using JavaScript/TypeScript. * **Handles Secure Auth Flows** – Support for email, social logins, wallet and passkey authentication. * **Simplifies Blockchain Interactions** – Manages signing and gasless transaction flows using Meta Accounts and Treasury contracts. * **Session Persistence** – Built-in support for persistent logins using `AsyncStorage`. * **Abstraxion Hooks** – React Native optimized hooks with the same interfaces as **`@burnt-labs/abstraxion-react`** on web. With this package, developers can quickly create friendly onboarding experiences and interact with smart contracts as easily as making a POST request in a traditional app. # Set up your Mobile Development Environment To build a mobile app on **Verona** with **React Native** and **Expo**, your development environment must support either **Android** or **iOS**. This guide walks you through the steps to initialize a **React Native** mobile app with **Expo** and configure it to work with Verona using the `@burnt-labs/abstraxion-react-native` package and have it running on either **Android** or **iOS**. The following is also a very useful [guide](https://docs.expo.dev/guides/local-app-development) that will help you set up your local development environment for **Expo**. ## Android Setup ### Install Java Development Kit The Java Development Kit (JDK) is required for Android development. The following instructions will help you to install JDK on your operating system. {% tabs %} {% tab title="macOS" %} Use Homebrew to install the **Azul Zulu OpenJDK**, which supports both **Intel** and **Apple Silicon** Macs. In your terminal, run: ```bash brew install --cask zulu@17 ``` Once the installation is complete, set the `JAVA_HOME` environment variable by adding the following to your `~/.bash_profile` (or `~/.zshrc` if you're using Zsh): ```bash export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home ``` {% endtab %} {% tab title="Linux" %} You can get [OpenJDK](http://openjdk.java.net/) either through your system’s package manager or by downloading it directly from [AdoptOpenJDK](https://adoptopenjdk.net/). {% endtab %} {% tab title="Windows" %} #### Requirements Before proceeding, ensure you have a package manager like [**Chocolatey**](https://chocolatey.org/install) set up on your system. #### Install Required Tools To install the Java SE Development Kit (JDK), run the following command in your terminal: ```bash choco install -y microsoft-openjdk17 ``` {% endtab %} {% endtabs %} ### **Install Android Studio** * Download: [Android Studio](https://developer.android.com/studio) * During setup, install: * **Android SDK** * **Android SDK Platform-Tools** * **Android Virtual Device (AVD) Manager** * Go to **Tools** > **SDK Manager** menu item and within that window go to **Settings** > **Languages & Frameworks** > **Android SDK**. From the SDK Platforms tab, select the latest Android version (API level). * Click on the **SDK Tools** tab and make sure you have at least one version of the Android SDK Build-Tools and Android Emulator installed. ### **Set Up Android Emulator** * Open **Android Studio > Device Manager** * Create a new virtual device (recommended: Pixel 9 with API 35+) ### **Add Environment Variables (macOS/Linux)** Add to your shell config (e.g., `~/.bashrc` or `~/.zshrc`): ```bash export ANDROID_HOME=$HOME/Library/Android/sdk export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=$PATH:$ANDROID_HOME/platform-tools ``` Then run: ```bash source ~/.zshrc # or your respective shell file ``` ## iOS Setup (macOS only) ### **Install Xcode** * Download from the [Mac App Store](https://apps.apple.com/us/app/xcode/id497799835) * Install **Command Line Tools** via your terminal by executing: ```bash xcode-select --install ``` ### Install an iOS Simulator To install an iOS Simulator, open **Xcode** > **Settings**... > **Components**, and under **Platform Support** > **iOS** ..., click **Get**. For more detailed guidance on configuring your development environment, refer to the official Expo setup guide: <https://docs.expo.dev/get-started/set-up-your-environment/>. # Building a React Native Mobile App with Abstraxion Mobile apps are an integral part of modern life, and therefore integrating Verona into mobile applications is a crucial step toward mass adoption. This guide will walk you through creating a React Native app using [**Expo**](https://expo.dev) and the [**Abstraxion** authentication system](https://github.com/burnt-labs/xion.js), based on the [**Abstraxion Expo Demo**](https://github.com/burnt-labs/abstraxion-expo-demo). ## Prerequisites Before you begin, ensure you have the following installed: * [**Node.js** (LTS version recommended) and **NPM**](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) * **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. ```bash npx create-expo-app@latest abstraxion-app --template default ``` You’ll be prompted to name your app. Once the setup is complete, navigate into the project directory: ```bash cd abstraxion-app ``` ### Install Required Dependencies Install the necessary dependencies for **Abstraxion** and other required libraries: ```bash 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 ``` These libraries enable authentication, cryptographic operations, and secure storage. ### Update Project Configuration #### Modify `app.json` Update the `app.json` file to configure your app’s package name (for Android apps) or bundle identifier (for IOS apps). **For Android:** Add the following under the `"android"` section changing the value to your unique identifier: ```json "package": "com.anonymous.abstraxionexpodemo" ``` **For iOS:** Add the following under the `"ios"` section: ```json "bundleIdentifier": "com.anonymous.abstraxionexpodemo" ``` {% hint style="warning" %} **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. {% endhint %} ### 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: ```typescript import { useState } from "react"; import { View, StyleSheet, Text, TouchableOpacity, Alert } from "react-native"; import { useAbstraxionAccount, useAbstraxionSigningClient, } from "@burnt-labs/abstraxion-react-native"; export default function Index() { const { data: account, logout, login, isConnected, isConnecting, } = useAbstraxionAccount(); const { client, signArb } = useAbstraxionSigningClient(); const [signArbResponse, setSignArbResponse] = useState(""); const [txHash, setTxHash] = useState(""); const [loadingInstantiate, setLoadingInstantiate] = useState(false); async function handleInstantiate() { setLoadingInstantiate(true); try { const msg = { type_urls: ["/cosmwasm.wasm.v1.MsgInstantiateContract"], grant_configs: [ { description: "Ability to instantiate contracts", optional: false, authorization: { type_url: "/cosmos.authz.v1beta1.GenericAuthorization", value: "CigvY29zbXdhc20ud2FzbS52MS5Nc2dJbnN0YW50aWF0ZUNvbnRyYWN0", }, }, ], fee_config: { description: "Sample fee config for testnet-2", allowance: { type_url: "/cosmos.feegrant.v1beta1.BasicAllowance", value: "Cg8KBXV4aW9uEgY1MDAwMDA=", }, }, admin: account.bech32Address, }; const instantiateRes = await client?.instantiate( account.bech32Address, 33, msg, "instantiate on expo demo", "auto" ); if (!instantiateRes) { throw new Error("Instantiate failed."); } setTxHash(instantiateRes.transactionHash); } catch (error) { Alert.alert("Error", (error as Error).message); } finally { setLoadingInstantiate(false); } } async function handleSign(): Promise<void> { if (client?.grantee
프로젝트로 돌아가기