Initia 백서

Initia

원문

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

dependencies (`wagmi`, `viem`, `@tanstack/react-query`) * [ ] Updated all import statements </Accordion> <Accordion title="✅ Configuration Cleanup"> * [ ] Removed SSR-related imports - \[ ] Removed build configuration changes - \[ ] Removed CDN scripts - \[ ] Updated provider configuration </Accordion> <Accordion title="✅ API Updates"> * [ ] Replaced `WalletWidgetProvider` with `InterwovenKitProvider` - \[ ] Updated `useWallet` to `useInterwovenKit` - \[ ] Migrated method calls (`onboard` → `openConnect`, etc.) - \[ ] Updated transaction handling (`requestTx` → `requestTxBlock`) </Accordion> <Accordion title="✅ Testing"> * [ ] Wallet connection works correctly * [ ] Bridge functionality works * [ ] Transaction submission works * [ ] No console errors or warnings </Accordion> </AccordionGroup> <Note> Need help with migration? Check out the [Getting Started guide](./getting-started) for complete implementation examples, or refer to the [API Reference](./references/index) for detailed method documentation. </Note> # InterwovenKitProvider Source: https://docs.initia.xyz/interwovenkit/references/components/interwovenkit-provider ## Overview * React provider that configures and renders the InterwovenKit widget shell (drawer, routes, and supporting providers). * Mount once near the top of your app, wrapping your root component. * AutoSign is optional. Enable it with `enableAutoSign` when you want signature-derived automatic signing flows. ## Prerequisites * Must be used within a React Query `QueryClientProvider`. * Must be used within a wagmi `WagmiProvider` if using wallet-related APIs. * Client-only (no SSR): Put this in a `use client` provider tree, or use a dynamic import in Next.js. ## Styles * CSS styles must be injected manually using [`injectStyles`](../utilities/inject-styles) once at app startup. Otherwise the UI will be unstyled. ## Quickstart ```tsx theme={null} 'use client' import { useEffect } from 'react' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { createConfig, http, WagmiProvider } from 'wagmi' import { mainnet } from 'wagmi/chains' import { initiaPrivyWalletConnector, injectStyles, InterwovenKitProvider, MAINNET, } from '@initia/interwovenkit-react' import interwovenKitStyles from '@initia/interwovenkit-react/styles.js' const queryClient = new QueryClient() const wagmiConfig = createConfig({ connectors: [initiaPrivyWalletConnector], chains: [mainnet], transports: { [mainnet.id]: http() }, }) export function AppProviders({ children }: { children: React.ReactNode }) { useEffect(() => { injectStyles(interwovenKitStyles) }, []) return ( <QueryClientProvider client={queryClient}> <WagmiProvider config={wagmiConfig}> <InterwovenKitProvider {...MAINNET}>{children}</InterwovenKitProvider> </WagmiProvider> </QueryClientProvider> ) } ``` <Note> This example shows the provider structure. For complete setup configurations, see [Provider Setup](../setup/providers). </Note> ## Props | Prop | Type | Default | Description | | ------------------------ | ------------------------------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `defaultChainId` | `string` | From preset | Initia or rollup chain ID that InterwovenKit should treat as the "home" chain | | `registryUrl` | `string` | From preset | Base URL for the Initia registry API used to resolve chains and assets | | `routerApiUrl` | `string` | From preset | Base URL for the router API used by the bridge and swap flows | | `glyphUrl` | `string` | From preset | Base URL for Glyph profile data (user avatars and related metadata) | | `usernamesModuleAddress` | `string` | From preset | On‑chain module address of the Initia (`.init`) username contract | | `lockStakeModuleAddress` | `string` | From preset | On-chain module address used for lock/stake position queries | | `minityUrl` | `string` | From preset | Base URL for Minity portfolio streaming and related portfolio APIs | | `dexUrl` | `string` | From preset | Base URL for DEX-related data used by portfolio and positions | | `vipUrl` | `string` | From preset | Base URL for VIP-related data used by portfolio and positions | | `theme` | `"light" \| "dark"` | From preset (typically dark) | Visual theme for the widget | | `customChain` | `Chain` | `undefined` | Adds or overrides a chain definition in the Initia registry. Use when you run a private rollup or need to inject a chain that is not yet in the public registry | | `protoTypes` | `Iterable<[string, GeneratedType]>` | `undefined` | Additional protobuf type mappings used when encoding Cosmos transactions. Only needed if you use custom message types | | `aminoConverters` | `AminoConverters` | `undefined` | Custom Amino converters for legacy signing. Only needed for advanced integrations | | `container` | `HTMLElement` | `undefined` | Optional element the widget should render into instead of the default Shadow DOM host | | `disableAnalytics` | `boolean` | `false` (mainnet), `true` (testnet) | When `true`, disables InterwovenKit's built‑in analytics events | | `enableAutoSign` | `boolean \| Record<string, string[]>` | `undefined` | Enables AutoSign and optionally whitelists chains and message types. `true` enables the default message type for the current default chain. `Record<string, string[]>` is a per-chain allowlist of message type URLs | | `autoSignFeePolicy` | `Record<string, AutoSignFeePolicy>` | `undefined` | Optional per-chain fee policy overrides for AutoSign gas multiplier and allowed fee denoms | ## Return Value Renders `children` and mounts the InterwovenKit UI shell. ## Examples ### Custom Chain Configuration ```tsx theme={null} import type { Chain } from '@initia/initia-registry-types' import { InterwovenKitProvider, MAINNET } from '@initia/interwovenkit-react' const MY_ROLLUP: Chain = { chain_id: 'my-rollup-1', chain_name: 'my-rollup', pretty_name: 'My Rollup', network_type: 'mainnet', bech32_prefix: 'init', fees: { fee_tokens: [ { denom: 'uinit', fixed_min_gas_price: 0.1, }, ], }, apis: { rpc: [{ address: 'https://rpc.my-rollup.com' }], rest: [{ address: 'https://api.my-rollup.com' }], indexer: [{ address: 'https://indexer.my-rollup.com' }], }, } as Chain export function Providers({ children }: { children: React.ReactNode }) { return ( <InterwovenKitProvider {...MAINNET} defaultChainId={MY_ROLLUP.chain_id} customChain={MY_ROLLUP} > {children} </InterwovenKitProvider> ) } ``` <Note> This example shows only the `InterwovenKitProvider` configuration. For complete provider setup including `QueryClientProvider`, `WagmiProvider`, and `injectStyles`, see [Provider Setup](../setup/providers). </Note> ## Notes * For end-to-end setup examples, see [Provider Setup](../setup/providers). ## Type Reference (Advanced) ```ts theme={null} type InterwovenKitProviderProps = React.PropsWithChildren<Partial<Config>> type Config = { defaultChainId: string customChain?: Chain protoTypes?: Iterable<[string, GeneratedType]> aminoConverters?: AminoConverters registryUrl: string routerApiUrl: string glyphUrl: string usernamesModuleAddress: string lockStakeModuleAddress: string minityUrl: string dexUrl: string vipUrl: string theme: 'light' | 'dark' container?: HTMLElement disableAnalytics?: boolean enableAutoSign?: boolean | Record<string, string[]> autoSignFeePolicy?: Record<string, AutoSignFeePolicy> } ``` Types `Chain`, `GeneratedType`, `AminoConverters`, and `AutoSignFeePolicy` are from InterwovenKit source and its external dependencies. See `@initia/initia-registry-types`, `@cosmjs/proto-signing`, and `@cosmjs/stargate` for related external types. # DEFAULT_GAS_ADJUSTMENT Source: https://docs.initia.xyz/interwovenkit/references/constants/default-gas-adjustment ## Overview * Default gas adjustment multiplier used when `gasAdjustment` is not provided in transaction requests. * Reference only if you need to match InterwovenKit's default in custom logic. ## Quickstart ```ts theme={null} import { DEFAULT_GAS_ADJUSTMENT } from "@initia/interwovenkit-react" // Pass explicit gasAdjustment to match InterwovenKit's default const { requestTxBlock } = useInterwovenKit() await requestTxBlock({ messages: [...], gasAdjustment: DEFAULT_GAS_ADJUSTMENT, // Optional: defaults to this value if omitted }) ``` ## Value ```ts theme={null} const DEFAULT_GAS_ADJUSTMENT: number // 1.4 ``` ## Notes * InterwovenKit uses this automatically when `gasAdjustment` is omitted. * Reference only if you need to match the default in custom logic. # DEFAULT_GAS_PRICE_MULTIPLIER Source: https://docs.initia.xyz/interwovenkit/references/constants/default-gas-price-multiplier ## Overview * Default gas price multiplier used for non-INIT fee tokens on Layer 1 chains. * Reference only if you need to reproduce InterwovenKit's fee calculation logic. ## Quickstart ```ts theme={null} import { DEFAULT_GAS_PRICE_MULTIPLIER } from '@initia/interwovenkit-react' // Reproduce InterwovenKit's fee calculation logic const adjustedPrice = baseGasPrice * DEFAULT_GAS_PRICE_MULTIPLIER ``` ## Value ```ts theme={null} const DEFAULT_GAS_PRICE_MULTIPLIER: number // 1.05 ``` ## Notes * InterwovenKit applies this automatically when suggesting fees. * Reference only if building custom fee calculation logic that needs to match InterwovenKit's behavior. # MAINNET Source: https://docs.initia.xyz/interwovenkit/references/constants/mainnet ## Overview * Configuration preset for Initia mainnet with defaults for registry, router, glyph, and username services. * Use as a starting point for production apps. ## Quickstart ```tsx theme={null} import { InterwovenKitProvider, MAINNET } from '@initia/interwovenkit-react' export function Providers({ children }: { children: React.ReactNode }) { return <InterwovenKitProvider {...MAINNET}>{children}</InterwovenKitProvider> } ``` ## Value ```ts theme={null} const MAINNET: { defaultChainId: 'interwoven-1' registryUrl: 'https://registry.initia.xyz' routerApiUrl: 'https://router-api.initia.xyz' glyphUrl: 'https://glyph.initia.xyz' usernamesModuleAddress: '0x72ed9b26ecdcd6a21d304df50f19abfdbe31d2c02f60c84627844620a45940ef' lockStakeModuleAddress: '0x3a886b32a802582f2e446e74d4a24d1d7ed01adf46d2a8f65c5723887e708789' minityUrl: 'https://portfolio-api.minity.xyz' dexUrl: 'https://dex-api.initia.xyz' vipUrl: 'https://vip-api.initia.xyz' theme: 'dark' } ``` **Property descriptions:** * `usernamesModuleAddress`: On-chain module address of the Initia (`.init`) username contract. This is the same for all apps using mainnet and it represents the deployed contract address that handles username lookups (e.g., resolving `alice.init` to an address) * `lockStakeModuleAddress`: On-chain module address used for lock/stake position queries * `minityUrl`: Base URL for Minity-backed portfolio data * `dexUrl`: Base URL for DEX-backed portfolio and position data * `vipUrl`: Base URL for VIP-backed portfolio and position data * `theme`: Default theme is `"dark"`, but can be overridden to `"light"` when using the preset ## Notes * Most apps should start with `{...MAINNET}` and override only what they need (for example `defaultChainId` or `theme`). # PRIVY_APP_ID Source: https://docs.initia.xyz/interwovenkit/references/constants/privy-app-id ## Overview * Initia's shared Privy application ID used by bundled wallet helpers. * NOT your app's Privy ID. References Initia's shared Privy app (bundled social-login wallet). * Use when configuring login methods that include the Initia Privy wallet alongside your own Privy app. ## Prerequisites * Relevant only if you are using Privy. * Privy must be set up separately (see Privy documentation for setup). ## Quickstart ```tsx theme={null} import { PRIVY_APP_ID } from '@initia/interwovenkit-react' import { PrivyProvider } from '@privy-io/react-auth' export function Providers({ children }: { children: React.ReactNode }) { return ( <PrivyProvider appId="YOUR_PRIVY_APP_ID" config={{ loginMethodsAndOrder: { primary: [`privy:${PRIVY_APP_ID}`, 'detected_ethereum_wallets'], }, }} > {children} </PrivyProvider> ) } ``` <Note> This example shows only `PrivyProvider` configuration. For complete provider setup including `InterwovenKitProvider`, `WagmiProvider`, `QueryClientProvider`, and `injectStyles`, see [Provider Setup](../setup/providers). </Note> ## Value ```ts theme={null} const PRIVY_APP_ID: string ``` ## Notes * Do not pass this value as your `PrivyProvider` `appId`. It is only for referencing Initia's bundled wallet in login method configuration. * Your own Privy app ID must be set separately as shown in the example above. # TESTNET Source: https://docs.initia.xyz/interwovenkit/references/constants/testnet ## Overview * Configuration preset for Initia testnet with testnet registry, router, glyph, and username services. * Use for development or staging apps. ## Quickstart ```tsx theme={null} import { InterwovenKitProvider, TESTNET } from '@initia/interwovenkit-react' export function Providers({ children }: { children: React.ReactNode }) { return <InterwovenKitProvider {...TESTNET}>{children}</InterwovenKitProvider> } ``` ## Value ```ts theme={null} const TESTNET: { defaultChainId: 'initiation-2' registryUrl: 'https://registry.testnet.initia.xyz' routerApiUrl: 'https://router-api.initiation-2.initia.xyz' glyphUrl: 'https://glyph.initiation-2.initia.xyz' usernamesModuleAddress: '0x42cd8467b1c86e59bf319e5664a09b6b5840bb3fac64f5ce690b5041c530565a' lockStakeModuleAddress: '0x81c3ea419d2fd3a27971021d9dd3cc708def05e5d6a09d39b2f1f9ba18312264' minityUrl: 'https://portfolio-api.minity.xyz' dexUrl: 'https://dex-api.initiation-2.initia.xyz' vipUrl: 'https://vip-api.testnet.initia.xyz' theme: 'dark' disableAnalytics: true } ``` **Property descriptions:** * `usernamesModuleAddress`: On-chain module address of the Initia (`.init`) username contract. This is the same for all apps using testnet and it represents the deployed contract address that handles username lookups (e.g., resolving `alice.init` to an address) * `lockStakeModuleAddress`: On-chain module address used for lock/stake position queries * `minityUrl`: Base URL for Minity-backed portfolio data * `dexUrl`: Base URL for DEX-backed portfolio and position data * `vipUrl`: Base URL for VIP-backed portfolio and position data * `theme`: Default theme is `"dark"`, but can be overridden to `"light"` when using the preset ## Notes * Analytics are disabled by default on testnet via `disableAnalytics: true`. * Most apps should start with `{...TESTNET}` in non‑production environments and override only what they need. # MoveError Source: https://docs.initia.xyz/interwovenkit/references/errors/move-error ## Overview * Error type that carries parsed Move VM error metadata. * Thrown by transaction helpers on Move VM failures. * Use `instanceof MoveError` to identify and handle Move VM errors separately. ## Quickstart ```tsx theme={null} import { MoveError, useInterwovenKit } from '@initia/interwovenkit-react' import type { EncodeObject, StdFee } from '@cosmjs/stargate' function isMoveError(error: unknown): error is MoveError { return error instanceof MoveError } function MyComponent() { const { submitTxBlock } = useInterwovenKit() const handleSubmit = async (messages: EncodeObject[], fee: StdFee) => { try { await submitTxBlock({ messages, fee }) } catch (error) { if (isMoveError(error)) { console.error( `Move error in ${error.moduleName} at ${error.moduleAddress}: ${error.errorCode}`, error.originalError, ) } } } } ``` ## Properties ```ts theme={null} class MoveError extends Error { originalError: Error moduleAddress: string moduleName: string errorCode: string errorCodeHex: string isFromRegistry: boolean } ``` ## Notes * Use `instanceof MoveError` to branch UI or logging based on Move-specific metadata (`moduleAddress`, `moduleName`, `errorCode`). * `originalError` contains the original error with full message and stack trace. * `isFromRegistry` indicates whether the error message was resolved from the Initia error registry (more user-friendly when `true`). # useAddress Source: https://docs.initia.xyz/interwovenkit/references/hooks/use-address ## Overview * Returns the connected wallet address, adapting to the default chain's format (hex for `minievm`, bech32 for others). * Use when you need a single address that matches the default chain's format. ## Prerequisites * Must be rendered within `InterwovenKitProvider`. * Must be used within a React Query `QueryClientProvider`. * Must be used within a wagmi `WagmiProvider`. * Client-only (no SSR): Put this in a `use client` provider tree, or use a dynamic import in Next.js. ## Quickstart ```tsx theme={null} 'use client' import { useAddress } from '@initia/interwovenkit-react' function Address() { const address = useAddress() return <span>{address || 'Not connected'}</span> } ``` <Note> This example assumes providers are already set up. For complete setup configurations, see [Provider Setup](../setup/providers). </Note> ## Return Value ```ts theme={null} function useAddress(): string ``` Returns a hex address when the default chain is `minievm`, or an Initia bech32 address for other chain types. Returns an empty string when there is no connected address. ## Notes * Prefer this hook over chain-specific address hooks (`useHexAddress`, `useInitiaAddress`) when you need a single address that automatically adapts to the default chain's format. * Returns hex format for `minievm` chains, bech32 format for other chain types. # useHexAddress Source: https://docs.initia.xyz/interwovenkit/references/hooks/use-hex-address ## Overview * Returns the connected wallet address in hex format (always hex, regardless of chain type). * Use when you need a hex address for EVM-style tooling or a consistent hex format. ## Prerequisites * Must be rendered within `InterwovenKitProvider`. * Must be used within a React Query `QueryClientProvider`. * Must be used within a wagmi `WagmiProvider`. * Client-only (no SSR): Put this in a `use client` provider tree, or use a dynamic import in Next.js. ## Quickstart ```tsx theme={null} 'use client' import { useHexAddress } from '@initia/interwovenkit-react' function Address() { const address = useHexAddress() return <span>{address || 'Not connected'}</span> } ``` <Note> This example assumes providers are already set up. For complete setup configurations, see [Provider Setup](../setup/providers). </Note> ## Return Value ```ts theme={null} function useHexAddress(): string ``` Returns the Initia account address in hex format when a wallet is connected. Returns an empty string when there is no connected address. ## Notes * Always returns hex format, unlike `useAddress` which adapts to the default chain's format. * Use for EVM-style integrations or when you need a consistent hex format regardless of chain type. # useInitiaAddress Source: https://docs.initia.xyz/interwovenkit/references/hooks/use-initia-address ## Overview * Returns the connected wallet address in Initia bech32 format (always bech32, regardless of chain type). * Use when you always need a bech32 address, regardless of the default chain type. ## Prerequisites * Must be rendered within `InterwovenKitProvider`. * Must be used within a React Query `QueryClientProvider`. * Must be used within a wagmi `WagmiProvider`. * Client-only (no SSR): Put this in a `use client` provider tree, or use a dynamic import in Next.js. ## Quickstart ```tsx theme={null} 'use client' import { useInitiaAddress } from '@initia/interwovenkit-react' function Address() { const address = useInitiaAddress() re
프로젝트로 돌아가기