Initia 백서

Initia

원문

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

-react' function Username() { const { data, isLoading } = useUsernameQuery() if (isLoading) return <span>Loading…</span> return <span>{data ?? 'No username'}</span> } ``` ### Specific Address Pass an address to resolve the username for that address instead of the connected wallet. ```tsx theme={null} 'use client' import { useUsernameQuery } from '@initia/interwovenkit-react' function SenderUsername({ address }: { address: string }) { const { data } = useUsernameQuery(address) return <span>{data ?? address}</span> } ``` <Note> These examples assume providers are already set up. For complete setup configurations, see [Provider Setup](../setup/providers). </Note> ## Return Value ```ts theme={null} function useUsernameQuery(address?: string): UseQueryResult<string | null> ``` Returns a React Query `UseQueryResult<string | null>` object. The `data` property is: * `string` when a username exists (ends with `.init`) * `null` when no username exists or the address is invalid * `undefined` before the query has produced a value or when the query is disabled (for example, when neither an explicit address nor a connected wallet address is available) Type `UseQueryResult` is from `@tanstack/react-query`. ## Notes * If `address` is omitted, the hook falls back to the connected address from `useAddress()`. # Overview Source: https://docs.initia.xyz/interwovenkit/references/index The InterwovenKit React API provides components, hooks, and utilities for integrating Initia wallet connections, transaction signing, and UI flows into React applications. InterwovenKit is designed around a single provider (`InterwovenKitProvider`) that configures network and UI behavior, with hooks layered on top for state, UI control, and transactions. Most users start by configuring `InterwovenKitProvider` with a preset (`MAINNET` or `TESTNET`), then use hooks like `useInterwovenKit` or `useAddress` to read connection state and trigger UI flows. The API is organized into: * **Components**: React providers and UI components (`InterwovenKitProvider`) * **Hooks**: React hooks for connection state, transactions, and data (`useInterwovenKit`, `useAddress`, `usePortfolio`, etc.) * **Utilities**: Helper functions (`injectStyles`) * **Errors**: Error types thrown by the API (`MoveError`) * **Constants**: Configuration presets and default values (`MAINNET`, `TESTNET`, gas constants, `PRIVY_APP_ID`) * **Social Login**: Wagmi and RainbowKit helpers for social login (`initiaPrivyWalletConnector`, `initiaPrivyWallet`) ## Common Starting Points * **Provider setup**: See [Provider Setup](./setup/providers) for complete configuration (basic setup or AutoSign) * **Initial setup**: [`InterwovenKitProvider`](./components/interwovenkit-provider) with [`MAINNET`](./constants/mainnet) or [`TESTNET`](./constants/testnet) * **Inject styles**: Call [`injectStyles`](./utilities/inject-styles) before rendering InterwovenKit UI components * **Read connection state**: [`useAddress`](./hooks/use-address) or [`useInterwovenKit`](./hooks/use-interwovenkit) * **Open UI flows**: [`useInterwovenKit`](./hooks/use-interwovenkit) (`openConnect`, `openWallet`, `openBridge`) * **Send transactions**: [`useInterwovenKit`](./hooks/use-interwovenkit) (`requestTxBlock`, `submitTxBlock`) If you are new to InterwovenKit, start with [`InterwovenKitProvider`](./components/interwovenkit-provider) and [`useInterwovenKit`](./hooks/use-interwovenkit). Everything else builds on top of those two APIs. # Provider Setup Source: https://docs.initia.xyz/interwovenkit/references/setup/providers ## Overview * Complete provider setup for InterwovenKit with all required dependencies. * Two variants: basic setup and AutoSign setup. * Use the basic setup unless you need automatic signing for approved message types. ## Basic Setup For apps that don't need AutoSign. <Note> This setup uses `initiaPrivyWalletConnector` as a wagmi connector option for Initia's bundled social-login entry in the wallet list. </Note> ```tsx theme={null} 'use client' import { PropsWithChildren, useEffect } from 'react' import { createConfig, http, WagmiProvider } from 'wagmi' import { mainnet } from 'wagmi/chains' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { initiaPrivyWalletConnector, injectStyles, InterwovenKitProvider, MAINNET, } from '@initia/interwovenkit-react' import interwovenKitStyles from '@initia/interwovenkit-react/styles.js' const wagmiConfig = createConfig({ connectors: [initiaPrivyWalletConnector], chains: [mainnet], transports: { [mainnet.id]: http() }, }) const queryClient = new QueryClient() export default function Providers({ children }: PropsWithChildren) { useEffect(() => { injectStyles(interwovenKitStyles) }, []) return ( <QueryClientProvider client={queryClient}> <WagmiProvider config={wagmiConfig}> <InterwovenKitProvider {...MAINNET}>{children}</InterwovenKitProvider> </WagmiProvider> </QueryClientProvider> ) } ``` ## AutoSign Setup For apps that need AutoSign. Configure AutoSign directly on `InterwovenKitProvider`. ```tsx theme={null} 'use client' import { PropsWithChildren, useEffect } from 'react' import { createConfig, http, WagmiProvider } from 'wagmi' import { mainnet } from 'wagmi/chains' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { initiaPrivyWalletConnector, injectStyles, InterwovenKitProvider, MAINNET, } from '@initia/interwovenkit-react' import interwovenKitStyles from '@initia/interwovenkit-react/styles.js' const wagmiConfig = createConfig({ connectors: [initiaPrivyWalletConnector], chains: [mainnet], transports: { [mainnet.id]: http() }, }) const queryClient = new QueryClient() export default function Providers({ children }: PropsWithChildren) { useEffect(() => { injectStyles(interwovenKitStyles) }, []) return ( <QueryClientProvider client={queryClient}> <WagmiProvider config={wagmiConfig}> <InterwovenKitProvider {...MAINNET} // Option 1: Use boolean to enable the default message type for the // current default chain: // - minievm: /minievm.evm.v1.MsgCall // - miniwasm: /cosmwasm.wasm.v1.MsgExecuteContract // - default: /initia.move.v1.MsgExecute enableAutoSign={true} // Option 2: Specify exact message types per chain // enableAutoSign={{ // "interwoven-1": [ // "/cosmos.bank.v1beta1.MsgSend", // "/cosmos.staking.v1beta1.MsgDelegate", // ], // }} // Optional: tighten auto-sign fee selection per chain // autoSignFeePolicy={{ // "interwoven-1": { // gasMultiplier: 1.2, // maxGasMultiplierFromSim: 1.5, // allowedFeeDenoms: ["uinit"], // }, // }} > {children} </InterwovenKitProvider> </WagmiProvider> </QueryClientProvider> ) } ``` ## Notes * Call `injectStyles()` once at app startup to avoid duplicate style tags. * AutoSign derives its signing wallet from the connected wallet's signature flow. Configure it with `enableAutoSign` on `InterwovenKitProvider`. * **`enableAutoSign` configuration**: * **Boolean (`true`)**: Enables AutoSign with default message types based on chain type: * `minievm`: `/minievm.evm.v1.MsgCall` * `miniwasm`: `/cosmwasm.wasm.v1.MsgExecuteContract` * `default`: `/initia.move.v1.MsgExecute` * **Record (`Record<string, string[]>`)**: Per-chain allowlist of specific message type URLs. Use this to control exactly which message types can be auto-signed (e.g., `MsgSend`, `MsgDelegate`, `MsgExecute`). * Use `autoSignFeePolicy` when you need to restrict fee denoms or tune gas-multiplier behavior for AutoSign. # initiaPrivyWallet Source: https://docs.initia.xyz/interwovenkit/references/social-login/initia-privy-wallet ## Overview * RainbowKit wallet that enables social login (email, Google, X) in your RainbowKit wallets list. * Use it to add Initia's bundled social-login wallet to your RainbowKit wallet list. ## Prerequisites * Must be used with RainbowKit `getDefaultConfig` or `createConfig`. * Use this helper when you want Initia's bundled social-login wallet in your RainbowKit wallet list. ## Quickstart ```tsx theme={null} 'use client' import { PropsWithChildren } from 'react' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { WagmiProvider } from 'wagmi' import { mainnet } from 'wagmi/chains' import { getDefaultConfig, RainbowKitProvider } from '@rainbow-me/rainbowkit' import { metaMaskWallet } from '@rainbow-me/rainbowkit/wallets' import { initiaPrivyWallet } from '@initia/interwovenkit-react' import '@rainbow-me/rainbowkit/styles.css' const projectId = 'YOUR_WALLETCONNECT_PROJECT_ID' // Required: Get from https://cloud.walletconnect.com const rainbowConfig = getDefaultConfig({ appName: 'My dApp', projectId, chains: [mainnet], wallets: [ { groupName: 'Social', wallets: [initiaPrivyWallet], // Social logins - shows as "Socials" }, { groupName: 'Popular', wallets: [(params) => metaMaskWallet({ ...params, projectId })], // External wallets }, ], }) const queryClient = new QueryClient() export function Providers({ children }: PropsWithChildren) { return ( <QueryClientProvider client={queryClient}> <WagmiProvider config={rainbowConfig}> <RainbowKitProvider>{children}</RainbowKitProvider> </WagmiProvider> </QueryClientProvider> ) } ``` ## Return Value ```ts theme={null} const initiaPrivyWallet: Wallet ``` Type `Wallet` is from `@rainbow-me/rainbowkit`. ## Notes * Enables Initia's bundled social-login option. * Use alongside other RainbowKit wallets (MetaMask, WalletConnect, etc.). * Display name: "Socials". # initiaPrivyWalletConnector Source: https://docs.initia.xyz/interwovenkit/references/social-login/initia-privy-wallet-connector ## Overview * Wagmi connector that enables social login (email, Google, X) in your wagmi connector list. * Use it to add Initia's bundled social-login entry to your wagmi connector list. ## Prerequisites * Must be used with wagmi `createConfig`. * Use this helper when you want Initia's bundled social-login connector in your wagmi config. ## Quickstart ```tsx theme={null} 'use client' import { PropsWithChildren } from 'react' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { createConfig, http, WagmiProvider } from 'wagmi' import { mainnet } from 'wagmi/chains' import { initiaPrivyWalletConnector } from '@initia/interwovenkit-react' const wagmiConfig = createConfig({ connectors: [ initiaPrivyWalletConnector, // Social logins - shows as "Connect Socials" ], chains: [mainnet], transports: { [mainnet.id]: http() }, }) const queryClient = new QueryClient() export function Providers({ children }: PropsWithChildren) { return ( <QueryClientProvider client={queryClient}> <WagmiProvider config={wagmiConfig}>{children}</WagmiProvider> </QueryClientProvider> ) } ``` ## Return Value ```ts theme={null} const initiaPrivyWalletConnector: Connector ``` Type `Connector` is from `wagmi`. ## Notes * Enables Initia's bundled social-login option. * Use alongside other wagmi connectors (MetaMask, WalletConnect, etc.). * Display name: "Connect Socials". # injectStyles Source: https://docs.initia.xyz/interwovenkit/references/utilities/inject-styles ## Overview * Injects CSS into InterwovenKit's Shadow DOM by appending a `<style>` element. * Required for correct visual rendering. Must be called before rendering InterwovenKit components. * Call once at app startup in your top-level Providers component. * Browser-only (requires `document`). ## Prerequisites * Must be called in a browser environment (`document` must exist). * Client-only (no SSR): Put this in a `use client` provider tree, or use a dynamic import in Next.js. * Should be called before `InterwovenKitProvider` renders (typically in the same component). ## Quickstart ```tsx theme={null} "use client" import { PropsWithChildren, useEffect } from "react" import { QueryClient, QueryClientProvider } from "@tanstack/react-query" import { WagmiProvider } from "wagmi" import { injectStyles, InterwovenKitProvider, MAINNET, } from "@initia/interwovenkit-react" import interwovenKitStyles from "@initia/interwovenkit-react/styles.js" const queryClient = new QueryClient() const wagmiConfig = /* your wagmi config */ export default function Providers({ children }: PropsWithChildren) { useEffect(() => { injectStyles(interwovenKitStyles) }, []) return ( <QueryClientProvider client={queryClient}> <WagmiProvider config={wagmiConfig}> <InterwovenKitProvider {...MAINNET}> {children} </InterwovenKitProvider> </WagmiProvider> </QueryClientProvider> ) } ``` <Note> This example shows the typical usage pattern. For complete setup configurations, see [Provider Setup](../setup/providers). </Note> ## API ```ts theme={null} function injectStyles(css: string): void ``` Injects the provided CSS string into InterwovenKit's Shadow DOM. The `css` parameter should be a string containing CSS rules. Returns `void`. ## Notes * Each call appends a new `<style>` element to the Shadow DOM. * For complete setup configurations, see [Provider Setup](../setup/providers). # Deploying Rollups Source: https://docs.initia.xyz/nodes-and-rollups/deploying-rollups/deploy Learn how to deploy your own rollup on Initia <Steps> <Step title="Install Weave"> To get started, you need to first install our [Weave CLI](https://github.com/initia-labs/weave). <CodeGroup> ```bash macOS theme={null} brew install initia-labs/tap/weave ``` ```bash Linux (AMD64) theme={null} VERSION=$(curl -s https://api.github.com/repos/initia-labs/weave/releases/latest | grep '"tag_name":' | cut -d'"' -f4 | cut -c 2-) wget https://github.com/initia-labs/weave/releases/download/v$VERSION/weave-$VERSION-linux-amd64.tar.gz tar -xvf weave-$VERSION-linux-amd64.tar.gz ``` ```bash Linux (ARM64) theme={null} VERSION=$(curl -s https://api.github.com/repos/initia-labs/weave/releases/latest | grep '"tag_name":' | cut -d'"' -f4 | cut -c 2-) wget https://github.com/initia-labs/weave/releases/download/v$VERSION/weave-$VERSION-linux-arm64.tar.gz tar -xvf weave-$VERSION-linux-arm64.tar.gz ``` ```bash From Source theme={null} git clone https://github.com/initia-labs/weave.git cd weave git checkout tags/v0.0.2 VERSION=$(curl -s https://api.github.com/repos/initia-labs/weave/releases/latest | grep '"tag_name":' | cut -d'"' -f4 | cut -c 2-) git checkout tags/v$VERSION make install ``` </CodeGroup> </Step> <Step title="Configure Weave and Gas Station Account"> With Weave installed, you need to set up and fund your [gas station account](/developers/developer-guides/tools/clis/weave-cli/gas-station). This account will be used to fund the various bots and processes involved in the rollup's operations. ```sh theme={null} weave init ``` This will prompt you to either generate a new account to use as your gas station account or import an existing account's mnemonic. Once you have created your account, you then need to fund it with some INIT tokens (for OPinit bots bridging transactions) and TIA (for submitting data to Celestia). </Step> <Step title="Deploy the Rollup"> Now that you have configured your gas station account, you can proceed to deploy your rollup. ```sh theme={null} weave rollup launch ``` From the provided options, you can: * Select your VM * Select your Chain ID and default gas token denomination * Select your DA layer * Enable the price oracle * Set genesis accounts For more information about a specific option, press `ctrl+T` to access the tooltip. To go back to the previous step, press `ctrl+Z`. <Warning> To ensure that you have tokens available to send transactions on your rollup, you should add at least 1 address you control to the list of genesis accounts when prompted. </Warning> Once you have selected all the options, Weave automatically starts the rollup. When complete, you will see the rollup's endpoint information, including REST, RPC, and (for EVM rollups) JSON-RPC endpoints. The CLI also creates a magic link that you can use to add your rollup to InitiaScan. ```sh theme={null} # Example output Rollup Endpoints: • REST API: http://localhost:1317 • RPC: http://localhost:26657 • RPC-WS: ws://localhost:26657/websocket • gRPC: http://localhost:9090 ✨ Explore your new rollup here 🪄 (We already started the rollup app for you) https://scan.testnet.initia.xyz/custom-network/add/link?config=eyJ2bSI6Im1vdmUiLCJjaGFpbklkIjoiZGVtby0zMTQiLCJtaW5HYXNQcmljZSI6MCwiZGVub20iOiJ1bWluIiwibGNkIjoiaHR0cDovL2xvY2FsaG9zdDoxMzE3IiwicnBjIjoiaHR0cDovL2xvY2FsaG9zdDoyNjY1NyJ9 i Important We recommend opening this in Chrome because some browsers may not support localhost access from a different host, or you can edit your browser's settings to allow it if necessary. ``` At this point, you can interact with your rollup, send transactions, and deploy contracts. For full functionality, you also need to run the OPinit Executor and Challenger bots and the IBC Relayer. <Note> At this stage, you can interact with your rollup, deploy contracts, and send transactions. To enable bridging INIT and other tokens from L1, setting up DA, and more, you also need to run the OPinit Executor, Challenger bots, and the IBC Relayer. Follow the steps below to set these up. </Note> </Step> <Step title="Start the OPinit Executor"> The OPinit Executor bot is responsible for executing INIT bridging transactions between the Initia L1 and your rollup, submitting the rollup state output to the L1, submitting DA data to Celestia, and more. To start the bot, run: ```sh theme={null} weave opinit init ``` This will prompt you to set up the bot's configuration through a series of questions. ```sh theme={null} ✓ Existing keys in /Users/tansawit/.minitia/artifacts/config.json detected. Would you like to add these to the keyring before proceeding? > Yes, use detected keys ✓ Which bot would you like to run? > Executor ✓ Please select an option for the system key for Oracle Bridge Executor > Generate new system key ✓ Existing /Users/tansawit/.minitia/artifacts/config.json detected. Would you like to use the data in this file to pre-fill some fields? > Yes, prefill ✓ Specify listen address of the bot ... localhost:3000 ✓ Specify L1 RPC endpoint ... https://rpc.testnet.initia.xyz:443/ ✓ Specify rollup chain ID ... demo-314 ✓ Specify rollup RPC endpoint ... http://localhost:26657 ✓ Specify rollup gas denom ... umin ✓ OPInit bot setup successfully. Config file is saved at /Users/tansawit/.opinit/executor.json. Feel free to modify it as needed. ✓ You can start the bot by running `weave opinit start executor` ``` Once all of that is complete, you can start the bot by running the following command. ```sh theme={null} weave opinit start executor ``` You should see the bot running in the terminal. ```sh theme={null} Streaming logs from launchd com.opinitd.executor.daemon 2025-02-11T17:28:42.094+0700 INFO executor executor/executor.go:80 bridge info {"id": 659, "submission_interval": 60} 2025-02-11T17:28:42.508+0700 INFO executor node/node.go:118 initialize height 2025-02-11T17:28:42.525+0700 INFO executor node/node.go:118 initialize height 2025-02-11T17:28:42.631+0700 INFO executor node/node.go:118 initialize height 2025-02-11T17:28:43.844+0700 INFO executor node/node.go:118 initialize height 2025-02-11T17:28:43.845+0700 INFO executor host/host.go:88 host start {"height": 5315486} 2025-02-11T17:28:43.845+0700 INFO executor child/child.go:200 child start {"height": 1} 2025-02-11T17:28:43.845+0700 INFO executor batchsubmitter/batch_submitter.go:153 batch start {"height": 1} 2025-02-11T17:28:43.845+0700 INFO executor node/node.go:173 tx checker looper stopped 2025-02-11T17:28:43.845+0700 INFO executor celestia/celestia.go:98 celestia start 2025-02-11T17:28:43.950+0700 INFO executor child/child.go:138 initialize tree {"index": 1} ┌───────────────────────────────────────────
프로젝트로 돌아가기