@initia/interwovenkit-react 2.0.0-rc.3 → 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 +106 -171
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +1 -41
- package/dist/index.js +3020 -3275
- package/dist/styles.css +1 -1
- package/dist/styles.js +1 -1
- package/package.json +105 -101
package/README.md
CHANGED
|
@@ -1,217 +1,152 @@
|
|
|
1
1
|
# @initia/interwovenkit-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## What is Initia Wallet?
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
###
|
|
9
|
+
### Installation
|
|
67
10
|
|
|
68
|
-
Install
|
|
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
|
-
###
|
|
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
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
<
|
|
118
|
-
{
|
|
119
|
-
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
|
|
61
|
+
```tsx
|
|
62
|
+
// layout.tsx
|
|
63
|
+
import Providers from "./providers"
|
|
148
64
|
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
### `useInterwovenKit()`
|
|
157
|
-
|
|
158
|
-
Provides core package state and actions:
|
|
76
|
+
### Basic Example
|
|
159
77
|
|
|
160
|
-
|
|
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
|
-
|
|
166
|
-
|
|
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
|
-
|
|
172
|
-
|
|
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
|
-
|
|
175
|
-
|
|
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
|
-
|
|
178
|
-
|
|
111
|
+
const transactionHash = await requestTxSync({ messages })
|
|
112
|
+
console.log("Transaction sent:", transactionHash)
|
|
179
113
|
|
|
180
|
-
|
|
181
|
-
|
|
114
|
+
await waitForTxConfirmation({ txHash: transactionHash })
|
|
115
|
+
console.log("Transaction confirmed:", transactionHash)
|
|
116
|
+
}
|
|
182
117
|
|
|
183
|
-
|
|
184
|
-
|
|
118
|
+
const ETH = "move/edfcddacac79ab86737a1e9e65805066d8be286a37cb94f4884b892b0e39f954"
|
|
119
|
+
const USDC = "ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4"
|
|
185
120
|
|
|
186
|
-
|
|
187
|
-
|
|
121
|
+
const bridgeTransferDetails = {
|
|
122
|
+
srcChainId: "interwoven-1",
|
|
123
|
+
srcDenom: ETH,
|
|
124
|
+
dstChainId: "interwoven-1",
|
|
125
|
+
dstDenom: USDC,
|
|
126
|
+
}
|
|
188
127
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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 {
|
|
145
|
+
import type { PropsWithChildren } from "react"
|
|
146
|
+
import { InterwovenKitProvider, TESTNET } from "@initia/interwovenkit-react"
|
|
212
147
|
|
|
213
|
-
|
|
214
|
-
return <
|
|
148
|
+
export default function Providers({ children }: PropsWithChildren) {
|
|
149
|
+
return <InterwovenKitProvider {...TESTNET}>{children}</InterwovenKitProvider>
|
|
215
150
|
}
|
|
216
151
|
```
|
|
217
152
|
|