@initia/interwovenkit-react 2.0.0-rc.4 → 2.0.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,217 +1,191 @@
1
1
  # @initia/interwovenkit-react
2
2
 
3
- `@initia/interwovenkit-react` is a React SDK that provides hooks and components to integrate Initia blockchain wallet connection, bridge functionality, and transaction signing into your React applications.
3
+ InterwovenKit is a React library that provides components and hooks to connect dApps to Initia and Interwoven Rollups.
4
4
 
5
- ## Simple Example
5
+ ## Table of Contents
6
6
 
7
- Below is a minimal example to demonstrate core capabilities: connecting a wallet, opening the wallet drawer, opening the bridge drawer, and sending a transaction.
7
+ - [Features](#features)
8
+ - [Getting Started](#getting-started)
9
+ - [Installation](#installation)
10
+ - [Configure Providers](#configure-providers)
11
+ - [Basic Example](#basic-example)
12
+ - [Usage on Testnet](#usage-on-testnet)
13
+ - [Migrating From v1](#migrating-from-v1)
8
14
 
9
- ```tsx
10
- import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"
11
- import { truncate, useAddress, useInterwovenKit } from "@initia/interwovenkit-react"
15
+ ## Features
12
16
 
13
- const Example = () => {
14
- const address = useAddress()
15
- const { username, openConnect, openWallet, openBridge, requestTxBlock } = useInterwovenKit()
17
+ ### Connect
16
18
 
17
- if (!address) {
18
- return <button onClick={openConnect}>Connect</button>
19
- }
20
-
21
- const send = async () => {
22
- const messages = [
23
- {
24
- typeUrl: "/cosmos.bank.v1beta1.MsgSend",
25
- value: MsgSend.fromPartial({
26
- fromAddress: address,
27
- toAddress: address,
28
- amount: [{ amount: "1000000", denom: "uinit" }],
29
- }),
30
- },
31
- ]
19
+ Connect to external wallets. Supports multiple wallet providers including MetaMask and Keplr.
32
20
 
33
- const { transactionHash } = await requestTxBlock({ messages })
34
- console.log(transactionHash)
35
- }
21
+ ### Wallet
36
22
 
37
- return (
38
- <>
39
- <header>
40
- <button
41
- onClick={() =>
42
- openBridge({
43
- srcChainId: "interwoven-1",
44
- srcDenom: "ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4",
45
- dstChainId: "interwoven-1",
46
- dstDenom: "uinit",
47
- })
48
- }
49
- >
50
- Bridge
51
- </button>
52
-
53
- <button onClick={openWallet}>{truncate(username ?? address)}</button>
54
- </header>
55
-
56
- <main>
57
- <button onClick={send}>Send</button>
58
- </main>
59
- </>
60
- )
61
- }
62
- ```
23
+ Wallet interface for managing assets across Interwoven rollups:
63
24
 
64
- ## Getting Started
25
+ - View fungible tokens
26
+ - Browse NFT items
27
+ - Track transaction history
65
28
 
66
- ### Install Dependencies
29
+ ### Bridge
67
30
 
68
- Install the core package and required peer dependencies:
31
+ Cross-chain bridge and swap functionality:
69
32
 
70
- ```bash
71
- pnpm add @initia/interwovenkit-react
72
- ```
33
+ - Transfer assets between Initia and Interwoven rollups
34
+ - Swap tokens within and across chains
35
+ - Automatic route optimization for best rates
36
+ - Support for OP Bridge withdrawals
73
37
 
74
- ### Provider Setup
38
+ ### Transaction Signing
75
39
 
76
- You must install a wallet connector to inject a wallet into the app.
40
+ Transaction handling with detailed preview:
77
41
 
78
- ```bash
79
- pnpm add @tanstack/react-query wagmi
80
- ```
42
+ - Fee estimation with multiple fee token options
43
+ - Transaction simulation before signing
44
+ - Detailed message breakdown
81
45
 
82
- ⚠️ Refer to the examples below.
46
+ ## Getting Started
83
47
 
84
- - **Vite**: [examples/vite/src/Providers.tsx](https://github.com/initia-labs/interwovenkit/blob/main/examples/vite/src/Providers.tsx)
85
- - **Next.js**: [examples/nextjs/src/app/providers.tsx](https://github.com/initia-labs/interwovenkit/blob/main/examples/nextjs/src/app/providers.tsx)
48
+ ### Installation
86
49
 
87
- ```tsx
88
- import { InterwovenKit } from "@initia/interwovenkit-react"
50
+ Install `@initia/interwovenkit-react` along with its peer dependencies:
89
51
 
90
- const App = () => {
91
- return <InterwovenKit defaultChainId="YOUR_CHAIN_ID">{/* YOUR APP HERE */}</InterwovenKit>
92
- }
52
+ ```bash
53
+ pnpm add @initia/interwovenkit-react wagmi viem @tanstack/react-query
93
54
  ```
94
55
 
95
- **Using a custom chain configuration:**
56
+ ### Configure Providers
57
+
58
+ Wrap your app with providers:
96
59
 
97
60
  ```tsx
98
- import { ChainSchema } from "@initia/initia-registry-types/zod"
99
- import { InterwovenKit } from "@initia/interwovenkit-react"
100
-
101
- const customChain = ChainSchema.parse({
102
- chain_id: "YOUR_CHAIN_ID",
103
- chain_name: "YOUR_CHAIN_NAME",
104
- apis: {
105
- rpc: [{ address: "YOUR_RPC_URL" }],
106
- rest: [{ address: "YOUR_LCD_URL" }],
107
- },
108
- fees: {
109
- fee_tokens: [{ denom: "YOUR_FEE_DENOM", fixed_min_gas_price: 0.015 }],
110
- },
111
- bech32_prefix: "init",
112
- network_type: "mainnet",
61
+ // providers.tsx
62
+ "use client"
63
+
64
+ import { PropsWithChildren, useEffect } from "react"
65
+ import { createConfig, http, WagmiProvider } from "wagmi"
66
+ import { mainnet } from "wagmi/chains"
67
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
68
+ import {
69
+ initiaPrivyWalletConnector,
70
+ injectStyles,
71
+ InterwovenKitProvider,
72
+ } from "@initia/interwovenkit-react"
73
+ import InterwovenKitStyles from "@initia/interwovenkit-react/styles.js"
74
+
75
+ const wagmiConfig = createConfig({
76
+ connectors: [initiaPrivyWalletConnector],
77
+ chains: [mainnet],
78
+ transports: { [mainnet.id]: http() },
113
79
  })
80
+ const queryClient = new QueryClient()
81
+
82
+ export default function Providers({ children }: PropsWithChildren) {
83
+ useEffect(() => {
84
+ // Inject styles into the shadow DOM used by Initia Wallet
85
+ injectStyles(InterwovenKitStyles)
86
+ }, [])
114
87
 
115
- const App = () => {
116
88
  return (
117
- <InterwovenKit defaultChainId="YOUR_CHAIN_ID" customChain={customChain}>
118
- {/* YOUR APP HERE */}
119
- </InterwovenKit>
89
+ <QueryClientProvider client={queryClient}>
90
+ <WagmiProvider config={wagmiConfig}>
91
+ <InterwovenKitProvider defaultChainId="YOUR_CHAIN_ID">{children}</InterwovenKitProvider>
92
+ </WagmiProvider>
93
+ </QueryClientProvider>
120
94
  )
121
95
  }
122
96
  ```
123
97
 
124
- ## Configuration Interface
125
-
126
- ```ts
127
- interface Config {
128
- /** Wallet integration interface. */
129
- wallet?: {
130
- meta: { icon?: string; name: string }
131
- address: string
132
- getEthereumProvider: () => Promise<Eip1193Provider>
133
- sign: (message: string) => Promise<string>
134
- disconnect: () => void
135
- }
136
-
137
- /** The default chain ID for wallet connection (registered in initia-registry). Defaults to "interwoven-1". */
138
- defaultChainId?: string
139
-
140
- /** Custom chain configuration when your chain is not registered in initia-registry. */
141
- customChain?: Chain
142
-
143
- /** Protobuf message types for custom transaction signing. */
144
- protoTypes?: Iterable<[string, GeneratedType]>
98
+ Then wrap your application root:
145
99
 
146
- /** Amino converters for encoding/decoding custom messages. */
147
- aminoConverters?: AminoConverters
100
+ ```tsx
101
+ // layout.tsx
102
+ import Providers from "./providers"
148
103
 
149
- /** UI theme preference: "light" or "dark". */
150
- theme?: "light" | "dark"
104
+ export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
105
+ return (
106
+ <html>
107
+ <body>
108
+ <Providers>{children}</Providers>
109
+ </body>
110
+ </html>
111
+ )
151
112
  }
152
113
  ```
153
114
 
154
- ## React Hooks API
155
-
156
- ### `useInterwovenKit()`
115
+ ### Basic Example
157
116
 
158
- Provides core package state and actions:
117
+ Connect the wallet, check the balance, and send a transaction:
159
118
 
160
- ```ts
161
- interface UseInterwovenKitResult {
162
- /** Resolves to either the bech32 or hex address based on the current `minitia` type. */
163
- address: string
164
-
165
- /** Bech32-formatted Initia wallet address of the connected account. */
166
- initiaAddress: string
167
-
168
- /** Hex-encoded Ethereum-compatible address of the connected account. */
169
- hexAddress: string
119
+ ```tsx
120
+ // page.tsx
121
+ "use client"
170
122
 
171
- /** Optional username associated with the account. */
172
- username?: string | null
123
+ import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"
124
+ import { truncate } from "@initia/utils"
125
+ import { useInterwovenKit } from "@initia/interwovenkit-react"
126
+
127
+ export default function Home() {
128
+ const {
129
+ address,
130
+ username,
131
+ openConnect,
132
+ openWallet,
133
+ openBridge,
134
+ requestTxSync,
135
+ waitForTxConfirmation,
136
+ } = useInterwovenKit()
173
137
 
174
- /** Opens the wallet drawer UI. */
175
- openWallet(): void
138
+ const send = async () => {
139
+ const messages = [
140
+ {
141
+ typeUrl: "/cosmos.bank.v1beta1.MsgSend",
142
+ value: MsgSend.fromPartial({
143
+ fromAddress: address,
144
+ toAddress: address,
145
+ amount: [{ amount: "1000000", denom: "uinit" }],
146
+ }),
147
+ },
148
+ ]
176
149
 
177
- /** Opens the bridge drawer UI. */
178
- openBridge(defaultValues: Partial<FormValues>): void
150
+ const transactionHash = await requestTxSync({ messages })
151
+ console.log("Transaction sent:", transactionHash)
179
152
 
180
- /** Estimates gas required for a transaction. */
181
- estimateGas(txRequest: TxRequest): Promise<number>
153
+ await waitForTxConfirmation({ txHash: transactionHash })
154
+ console.log("Transaction confirmed:", transactionHash)
155
+ }
182
156
 
183
- /** Signs and broadcasts a transaction, waits for block inclusion, and returns the full transaction response. */
184
- requestTxBlock(txRequest: TxRequest): Promise<DeliverTxResponse>
157
+ const ETH = "move/edfcddacac79ab86737a1e9e65805066d8be286a37cb94f4884b892b0e39f954"
158
+ const USDC = "ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4"
185
159
 
186
- /** Signs and broadcasts a transaction and returns the transaction hash immediately. */
187
- requestTxSync(txRequest: TxRequest): Promise<string>
160
+ const bridgeTransferDetails = {
161
+ srcChainId: "interwoven-1",
162
+ srcDenom: ETH,
163
+ dstChainId: "interwoven-1",
164
+ dstDenom: USDC,
165
+ }
188
166
 
189
- /** Waits for a transaction to be confirmed on-chain. */
190
- waitForTxConfirmation(params: {
191
- txHash: string
192
- chainId?: string
193
- timeoutSeconds?: number
194
- intervalSeconds?: number
195
- }): Promise<IndexedTx>
196
- }
167
+ if (!address) {
168
+ return <button onClick={openConnect}>Connect</button>
169
+ }
197
170
 
198
- interface TxRequest {
199
- messages: EncodeObject[]
200
- memo?: string
201
- chainId?: string
202
- gasAdjustment?: number
203
- gas?: number
204
- fee?: StdFee | null
171
+ return (
172
+ <>
173
+ <button onClick={send}>Send</button>
174
+ <button onClick={() => openBridge(bridgeTransferDetails)}>Bridge</button>
175
+ <button onClick={openWallet}>{truncate(username ?? address)}</button>
176
+ </>
177
+ )
205
178
  }
206
179
  ```
207
180
 
208
181
  ## Usage on Testnet
209
182
 
210
183
  ```tsx
211
- import { InterwovenKit, TESTNET } from "@initia/interwovenkit-react"
184
+ import type { PropsWithChildren } from "react"
185
+ import { InterwovenKitProvider, TESTNET } from "@initia/interwovenkit-react"
212
186
 
213
- const App = () => {
214
- return <InterwovenKit {...TESTNET}>{/* YOUR APP HERE */}</InterwovenKit>
187
+ export default function Providers({ children }: PropsWithChildren) {
188
+ return <InterwovenKitProvider {...TESTNET}>{children}</InterwovenKitProvider>
215
189
  }
216
190
  ```
217
191