@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 +135 -161
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +2 -22
- package/dist/index.js +3584 -3340
- package/dist/styles.css +1 -1
- package/dist/styles.js +1 -1
- package/package.json +111 -109
package/README.md
CHANGED
|
@@ -1,217 +1,191 @@
|
|
|
1
1
|
# @initia/interwovenkit-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
InterwovenKit is a React library that provides components and hooks to connect dApps to Initia and Interwoven Rollups.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Table of Contents
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"
|
|
11
|
-
import { truncate, useAddress, useInterwovenKit } from "@initia/interwovenkit-react"
|
|
15
|
+
## Features
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
const address = useAddress()
|
|
15
|
-
const { username, openConnect, openWallet, openBridge, requestTxBlock } = useInterwovenKit()
|
|
17
|
+
### Connect
|
|
16
18
|
|
|
17
|
-
|
|
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
|
-
|
|
34
|
-
console.log(transactionHash)
|
|
35
|
-
}
|
|
21
|
+
### Wallet
|
|
36
22
|
|
|
37
|
-
|
|
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
|
-
|
|
25
|
+
- View fungible tokens
|
|
26
|
+
- Browse NFT items
|
|
27
|
+
- Track transaction history
|
|
65
28
|
|
|
66
|
-
###
|
|
29
|
+
### Bridge
|
|
67
30
|
|
|
68
|
-
|
|
31
|
+
Cross-chain bridge and swap functionality:
|
|
69
32
|
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
###
|
|
38
|
+
### Transaction Signing
|
|
75
39
|
|
|
76
|
-
|
|
40
|
+
Transaction handling with detailed preview:
|
|
77
41
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
42
|
+
- Fee estimation with multiple fee token options
|
|
43
|
+
- Transaction simulation before signing
|
|
44
|
+
- Detailed message breakdown
|
|
81
45
|
|
|
82
|
-
|
|
46
|
+
## Getting Started
|
|
83
47
|
|
|
84
|
-
|
|
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
|
-
|
|
88
|
-
import { InterwovenKit } from "@initia/interwovenkit-react"
|
|
50
|
+
Install `@initia/interwovenkit-react` along with its peer dependencies:
|
|
89
51
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
52
|
+
```bash
|
|
53
|
+
pnpm add @initia/interwovenkit-react wagmi viem @tanstack/react-query
|
|
93
54
|
```
|
|
94
55
|
|
|
95
|
-
|
|
56
|
+
### Configure Providers
|
|
57
|
+
|
|
58
|
+
Wrap your app with providers:
|
|
96
59
|
|
|
97
60
|
```tsx
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
<
|
|
118
|
-
{
|
|
119
|
-
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
|
|
100
|
+
```tsx
|
|
101
|
+
// layout.tsx
|
|
102
|
+
import Providers from "./providers"
|
|
148
103
|
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
### `useInterwovenKit()`
|
|
115
|
+
### Basic Example
|
|
157
116
|
|
|
158
|
-
|
|
117
|
+
Connect the wallet, check the balance, and send a transaction:
|
|
159
118
|
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
172
|
-
|
|
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
|
-
|
|
175
|
-
|
|
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
|
-
|
|
178
|
-
|
|
150
|
+
const transactionHash = await requestTxSync({ messages })
|
|
151
|
+
console.log("Transaction sent:", transactionHash)
|
|
179
152
|
|
|
180
|
-
|
|
181
|
-
|
|
153
|
+
await waitForTxConfirmation({ txHash: transactionHash })
|
|
154
|
+
console.log("Transaction confirmed:", transactionHash)
|
|
155
|
+
}
|
|
182
156
|
|
|
183
|
-
|
|
184
|
-
|
|
157
|
+
const ETH = "move/edfcddacac79ab86737a1e9e65805066d8be286a37cb94f4884b892b0e39f954"
|
|
158
|
+
const USDC = "ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4"
|
|
185
159
|
|
|
186
|
-
|
|
187
|
-
|
|
160
|
+
const bridgeTransferDetails = {
|
|
161
|
+
srcChainId: "interwoven-1",
|
|
162
|
+
srcDenom: ETH,
|
|
163
|
+
dstChainId: "interwoven-1",
|
|
164
|
+
dstDenom: USDC,
|
|
165
|
+
}
|
|
188
166
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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 {
|
|
184
|
+
import type { PropsWithChildren } from "react"
|
|
185
|
+
import { InterwovenKitProvider, TESTNET } from "@initia/interwovenkit-react"
|
|
212
186
|
|
|
213
|
-
|
|
214
|
-
return <
|
|
187
|
+
export default function Providers({ children }: PropsWithChildren) {
|
|
188
|
+
return <InterwovenKitProvider {...TESTNET}>{children}</InterwovenKitProvider>
|
|
215
189
|
}
|
|
216
190
|
```
|
|
217
191
|
|