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

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,152 @@
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
+ ## What is Initia Wallet?
4
4
 
5
- ## Simple Example
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.
8
-
9
- ```tsx
10
- import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"
11
- import { truncate, useAddress, useInterwovenKit } from "@initia/interwovenkit-react"
12
-
13
- const Example = () => {
14
- const address = useAddress()
15
- const { username, openConnect, openWallet, openBridge, requestTxBlock } = useInterwovenKit()
16
-
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
- ]
32
-
33
- const { transactionHash } = await requestTxBlock({ messages })
34
- console.log(transactionHash)
35
- }
36
-
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
- ```
5
+ Initia Wallet is a React library that provides components and hooks to connect dApps to Initia and Interwoven Rollups.
63
6
 
64
7
  ## Getting Started
65
8
 
66
- ### Install Dependencies
9
+ ### Installation
67
10
 
68
- Install the core package and required peer dependencies:
11
+ Install `@initia/interwovenkit-react` along with its peer dependencies:
69
12
 
70
13
  ```bash
71
- pnpm add @initia/interwovenkit-react
14
+ pnpm add @initia/interwovenkit-react wagmi viem @tanstack/react-query
72
15
  ```
73
16
 
74
- ### Provider Setup
75
-
76
- You must install a wallet connector to inject a wallet into the app.
77
-
78
- ```bash
79
- pnpm add @tanstack/react-query wagmi
80
- ```
17
+ ### Configure Providers
81
18
 
82
- ⚠️ Refer to the examples below.
83
-
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)
19
+ Wrap your app with providers:
86
20
 
87
21
  ```tsx
88
- import { InterwovenKit } from "@initia/interwovenkit-react"
89
-
90
- const App = () => {
91
- return <InterwovenKit defaultChainId="YOUR_CHAIN_ID">{/* YOUR APP HERE */}</InterwovenKit>
92
- }
93
- ```
94
-
95
- **Using a custom chain configuration:**
96
-
97
- ```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",
22
+ // providers.tsx
23
+ "use client"
24
+
25
+ import { PropsWithChildren, useEffect } from "react"
26
+ import { createConfig, http, WagmiProvider } from "wagmi"
27
+ import { mainnet } from "wagmi/chains"
28
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
29
+ import {
30
+ initiaPrivyWalletConnector,
31
+ injectStyles,
32
+ InterwovenKitProvider,
33
+ } from "@initia/interwovenkit-react"
34
+ import InterwovenKitStyles from "@initia/interwovenkit-react/styles.js"
35
+
36
+ const wagmiConfig = createConfig({
37
+ connectors: [initiaPrivyWalletConnector],
38
+ chains: [mainnet],
39
+ transports: { [mainnet.id]: http() },
113
40
  })
41
+ const queryClient = new QueryClient()
42
+
43
+ export default function Providers({ children }: PropsWithChildren) {
44
+ useEffect(() => {
45
+ // Inject styles into the shadow DOM used by Initia Wallet
46
+ injectStyles(InterwovenKitStyles)
47
+ }, [])
114
48
 
115
- const App = () => {
116
49
  return (
117
- <InterwovenKit defaultChainId="YOUR_CHAIN_ID" customChain={customChain}>
118
- {/* YOUR APP HERE */}
119
- </InterwovenKit>
50
+ <QueryClientProvider client={queryClient}>
51
+ <WagmiProvider config={wagmiConfig}>
52
+ <InterwovenKitProvider defaultChainId="interwoven-1">{children}</InterwovenKitProvider>
53
+ </WagmiProvider>
54
+ </QueryClientProvider>
120
55
  )
121
56
  }
122
57
  ```
123
58
 
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]>
59
+ Then wrap your application root:
145
60
 
146
- /** Amino converters for encoding/decoding custom messages. */
147
- aminoConverters?: AminoConverters
61
+ ```tsx
62
+ // layout.tsx
63
+ import Providers from "./providers"
148
64
 
149
- /** UI theme preference: "light" or "dark". */
150
- theme?: "light" | "dark"
65
+ export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
66
+ return (
67
+ <html>
68
+ <body>
69
+ <Providers>{children}</Providers>
70
+ </body>
71
+ </html>
72
+ )
151
73
  }
152
74
  ```
153
75
 
154
- ## React Hooks API
155
-
156
- ### `useInterwovenKit()`
157
-
158
- Provides core package state and actions:
76
+ ### Basic Example
159
77
 
160
- ```ts
161
- interface UseInterwovenKitResult {
162
- /** Resolves to either the bech32 or hex address based on the current `minitia` type. */
163
- address: string
78
+ Connect the wallet, check the balance, and send a transaction:
164
79
 
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
80
+ ```tsx
81
+ // page.tsx
82
+ "use client"
170
83
 
171
- /** Optional username associated with the account. */
172
- username?: string | null
84
+ import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"
85
+ import { truncate } from "@initia/utils"
86
+ import { useInterwovenKit } from "@initia/interwovenkit-react"
87
+
88
+ export default function Home() {
89
+ const {
90
+ address,
91
+ username,
92
+ openConnect,
93
+ openWallet,
94
+ openBridge,
95
+ requestTxSync,
96
+ waitForTxConfirmation,
97
+ } = useInterwovenKit()
173
98
 
174
- /** Opens the wallet drawer UI. */
175
- openWallet(): void
99
+ const send = async () => {
100
+ const messages = [
101
+ {
102
+ typeUrl: "/cosmos.bank.v1beta1.MsgSend",
103
+ value: MsgSend.fromPartial({
104
+ fromAddress: address,
105
+ toAddress: address,
106
+ amount: [{ amount: "1000000", denom: "uinit" }],
107
+ }),
108
+ },
109
+ ]
176
110
 
177
- /** Opens the bridge drawer UI. */
178
- openBridge(defaultValues: Partial<FormValues>): void
111
+ const transactionHash = await requestTxSync({ messages })
112
+ console.log("Transaction sent:", transactionHash)
179
113
 
180
- /** Estimates gas required for a transaction. */
181
- estimateGas(txRequest: TxRequest): Promise<number>
114
+ await waitForTxConfirmation({ txHash: transactionHash })
115
+ console.log("Transaction confirmed:", transactionHash)
116
+ }
182
117
 
183
- /** Signs and broadcasts a transaction, waits for block inclusion, and returns the full transaction response. */
184
- requestTxBlock(txRequest: TxRequest): Promise<DeliverTxResponse>
118
+ const ETH = "move/edfcddacac79ab86737a1e9e65805066d8be286a37cb94f4884b892b0e39f954"
119
+ const USDC = "ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4"
185
120
 
186
- /** Signs and broadcasts a transaction and returns the transaction hash immediately. */
187
- requestTxSync(txRequest: TxRequest): Promise<string>
121
+ const bridgeTransferDetails = {
122
+ srcChainId: "interwoven-1",
123
+ srcDenom: ETH,
124
+ dstChainId: "interwoven-1",
125
+ dstDenom: USDC,
126
+ }
188
127
 
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
- }
128
+ if (!address) {
129
+ return <button onClick={openConnect}>Connect</button>
130
+ }
197
131
 
198
- interface TxRequest {
199
- messages: EncodeObject[]
200
- memo?: string
201
- chainId?: string
202
- gasAdjustment?: number
203
- gas?: number
204
- fee?: StdFee | null
132
+ return (
133
+ <>
134
+ <button onClick={send}>Send</button>
135
+ <button onClick={() => openBridge(bridgeTransferDetails)}>Bridge</button>
136
+ <button onClick={openWallet}>{truncate(username ?? address)}</button>
137
+ </>
138
+ )
205
139
  }
206
140
  ```
207
141
 
208
142
  ## Usage on Testnet
209
143
 
210
144
  ```tsx
211
- import { InterwovenKit, TESTNET } from "@initia/interwovenkit-react"
145
+ import type { PropsWithChildren } from "react"
146
+ import { InterwovenKitProvider, TESTNET } from "@initia/interwovenkit-react"
212
147
 
213
- const App = () => {
214
- return <InterwovenKit {...TESTNET}>{/* YOUR APP HERE */}</InterwovenKit>
148
+ export default function Providers({ children }: PropsWithChildren) {
149
+ return <InterwovenKitProvider {...TESTNET}>{children}</InterwovenKitProvider>
215
150
  }
216
151
  ```
217
152