ia/interwovenkit-react'
export default function TransactionExample() {
const { address, requestTxBlock } = useInterwovenKit()
const [isLoading, setIsLoading] = useState(false)
const [lastTxHash, setLastTxHash] = useState<string>('')
const sendTransaction = async () => {
if (!address) return
setIsLoading(true)
try {
// Create a simple send transaction to yourself
const messages = [
{
typeUrl: '/cosmos.bank.v1beta1.MsgSend',
value: MsgSend.fromPartial({
fromAddress: address,
toAddress: address,
amount: [{ amount: '1000000', denom: 'uinit' }], // 1 INIT
}),
},
]
const { transactionHash } = await requestTxBlock({ messages })
setLastTxHash(transactionHash)
console.log('Transaction successful:', transactionHash)
} catch (error) {
console.error('Transaction failed:', error)
} finally {
setIsLoading(false)
}
}
if (!address) {
return <p>Please connect your wallet first</p>
}
return (
<div>
<h3>Send Transaction</h3>
<button onClick={sendTransaction} disabled={isLoading}>
{isLoading ? 'Sending...' : 'Send 1 INIT to Self'}
</button>
{lastTxHash && <p>Last transaction: {lastTxHash}</p>}
</div>
)
}
```
</Step>
<Step title="Custom Fee Handling (Optional)">
The custom fee handling feature allows you to bypass the "Confirm tx" modal and provide pre-calculated fees directly, giving you more control over transaction speed and UX. The requestTx functions are still available, so you can choose the workflow that fits your app best.
You can provide fees in two ways:
* `Pre-calculated`: Provide a fixed fee if you are confident.
* `Estimated`: Use estimateGas to simulate the required fee.
<Note>
Since this skips the standard fee selection UI, ensure the fee is displayed
somewhere else in your app to maintain transparency for users.
</Note>
```tsx components/TransactionExampleWithFee.tsx theme={null}
'use client'
import { useState } from 'react'
import { MsgSend } from 'cosmjs-types/cosmos/bank/v1beta1/tx'
import { calculateFee, GasPrice } from '@cosmjs/stargate'
import { useInterwovenKit } from '@initia/interwovenkit-react'
export default function TransactionExample() {
const { address, estimateGas, submitTxBlock } = useInterwovenKit()
const [isLoading, setIsLoading] = useState(false)
const [lastTxHash, setLastTxHash] = useState<string>('')
const sendTransaction = async () => {
if (!address) return
setIsLoading(true)
try {
// Create a simple send transaction to yourself
const messages = [
{
typeUrl: '/cosmos.bank.v1beta1.MsgSend',
value: MsgSend.fromPartial({
fromAddress: address,
toAddress: address,
amount: [{ amount: '1000000', denom: 'uinit' }], // 1 INIT
}),
},
]
// Estimate gas and calculate fee
const gas = await estimateGas({ messages })
const fee = calculateFee(gas, GasPrice.fromString('0.015uinit'))
const { transactionHash } = await submitTxBlock({ messages, fee })
setLastTxHash(transactionHash)
console.log('Transaction successful:', transactionHash)
} catch (error) {
console.error('Transaction failed:', error)
} finally {
setIsLoading(false)
}
}
if (!address) {
return <p>Please connect your wallet first</p>
}
return (
<div>
<h3>Send Transaction</h3>
<button onClick={sendTransaction} disabled={isLoading}>
{isLoading ? 'Sending...' : 'Send 1 INIT to Self'}
</button>
{lastTxHash && <p>Last transaction: {lastTxHash}</p>}
</div>
)
}
```
</Step>
</Steps>
# RainbowKit Integration
Source: https://docs.initia.xyz/interwovenkit/integrations/rainbowkit
Replace InterwovenKit's default connect UI with
[RainbowKit](https://rainbowkit.com) while preserving all Initia functionality.
Since InterwovenKit uses wagmi connectors internally, integrating RainbowKit
only changes the wallet connection interface—all other features remain
identical.
<Note>
This integration is perfect if you're already using RainbowKit in your
application or prefer its UI components over the default InterwovenKit
interface.
</Note>
## Overview
RainbowKit integration with InterwovenKit provides:
* **Familiar UI**: Keep using RainbowKit's polished wallet connection interface
* **Full Compatibility**: All InterwovenKit hooks and features work exactly the
same
* **Easy Migration**: Drop-in replacement for the default connect UI
* **Customization**: Full access to RainbowKit's theming and customization
options
## Integration Steps
<Steps>
<Step title="Install RainbowKit">
Add RainbowKit to your project dependencies:
<CodeGroup>
```sh npm theme={null}
npm install @rainbow-me/rainbowkit
```
```sh yarn theme={null}
yarn add @rainbow-me/rainbowkit
```
```sh pnpm theme={null}
pnpm add @rainbow-me/rainbowkit
```
```sh bun theme={null}
bun add @rainbow-me/rainbowkit
```
</CodeGroup>
</Step>
<Step title="Configure Providers">
Update your provider configuration to include RainbowKit:
```tsx theme={null}
// providers.tsx
"use client"
import { PropsWithChildren, useEffect } from "react"
import { createConfig, http, WagmiProvider } from "wagmi"
import { mainnet } from "wagmi/chains"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import { connectorsForWallets, RainbowKitProvider } from "@rainbow-me/rainbowkit"
import "@rainbow-me/rainbowkit/styles.css"
import { initiaPrivyWallet, injectStyles, InterwovenKitProvider } from "@initia/interwovenkit-react"
import interwovenKitStyles from "@initia/interwovenkit-react/styles.js"
const connectors = connectorsForWallets(
[
{
groupName: "Recommended",
wallets: [initiaPrivyWallet],
},
],
{
appName: "Your App Name",
projectId: "your-project-id",
}
)
const wagmiConfig = createConfig({
connectors,
chains: [mainnet],
transports: { [mainnet.id]: http() },
})
const queryClient = new QueryClient()
export default function Providers({ children }: PropsWithChildren) {
useEffect(() => {
// Inject styles into the shadow DOM used by Initia Wallet
injectStyles(interwovenKitStyles)
}, [])
return (
<QueryClientProvider client={queryClient}>
<WagmiProvider config={wagmiConfig}>
<RainbowKitProvider>
<InterwovenKitProvider defaultChainId="YOUR_CHAIN_ID">
{children}
</InterwovenKitProvider>
</RainbowKitProvider>
</WagmiProvider>
</QueryClientProvider>
)
}
```
<Info>
**Configuration Requirements:**
* Replace `YOUR_CHAIN_ID` with your target blockchain network:
* `"interwoven-1"` for Initia mainnet (default)
* `"initiation-2"` for Initia testnet
* Or any valid chain ID from the [initia-registry](https://registry.initia.xyz)
* Update `appName` and `projectId` to match your application details
The `defaultChainId` sets the primary network for all Initia Wallet operations. See [InterwovenKitProvider reference](/interwovenkit/references/components/interwovenkit-provider) for details.
</Info>
</Step>
<Step title="Use RainbowKit Components">
Replace InterwovenKit's connect UI with RainbowKit's `ConnectButton`:
```tsx theme={null}
// page.tsx
"use client"
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"
import { ConnectButton } from "@rainbow-me/rainbowkit"
import { truncate } from "@initia/utils"
import { useInterwovenKit } from "@initia/interwovenkit-react"
export default function Home() {
const { address, username, openWallet, openBridge, requestTxBlock } = useInterwovenKit()
const send = async () => {
const messages = [
{
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: MsgSend.fromPartial({
fromAddress: address,
toAddress: address,
amount: [{ amount: "1000000", denom: "uinit" }],
}),
},
]
const { transactionHash } = await requestTxBlock({ messages })
console.log("Transaction sent:", transactionHash)
}
const bridgeTransferDetails = {
srcChainId: "SOURCE_CHAIN_ID",
srcDenom: "SOURCE_ASSET_DENOM",
dstChainId: "DESTINATION_CHAIN_ID",
dstDenom: "DESTINATION_ASSET_DENOM",
}
if (!address) {
return <ConnectButton />
}
return (
<>
<button onClick={send}>Send</button>
<button onClick={() => openBridge(bridgeTransferDetails)}>Bridge</button>
<button onClick={openWallet}>{truncate(username ?? address)}</button>
</>
)
}
```
</Step>
<Step title="Custom Fee Handling (Optional)">
The custom fee handling feature allows you to bypass the "Confirm tx" modal and provide pre-calculated fees directly, giving you more control over transaction speed and UX. The requestTx functions are still available, so you can choose the workflow that fits your app best.
```tsx theme={null}
// page.tsx
"use client"
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"
import { ConnectButton } from "@rainbow-me/rainbowkit"
import { truncate } from "@initia/utils"
import { calculateFee, GasPrice } from "@cosmjs/stargate"
import { useInterwovenKit } from "@initia/interwovenkit-react"
export default function Home() {
const { address, username, openWallet, openBridge, estimateGas, submitTxBlock } = useInterwovenKit()
const send = async () => {
const messages = [
{
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
value: MsgSend.fromPartial({
fromAddress: address,
toAddress: address,
amount: [{ amount: "1000000", denom: "uinit" }],
}),
},
]
// Estimate gas and calculate fee
const gas = await estimateGas({ messages })
const fee = calculateFee(gas, GasPrice.fromString("0.015uinit"))
const { transactionHash } = await submitTxBlock({ messages, fee })
console.log("Transaction sent:", transactionHash)
}
const bridgeTransferDetails = {
srcChainId: "SOURCE_CHAIN_ID",
srcDenom: "SOURCE_ASSET_DENOM",
dstChainId: "DESTINATION_CHAIN_ID",
dstDenom: "DESTINATION_ASSET_DENOM",
}
if (!address) {
return <ConnectButton />
}
return (
<>
<button onClick={send}>Send</button>
<button onClick={() => openBridge(bridgeTransferDetails)}>Bridge</button>
<button onClick={openWallet}>{truncate(username ?? address)}</button>
</>
)
}
```
</Step>
</Steps>
# Introduction
Source: https://docs.initia.xyz/interwovenkit/introduction
InterwovenKit is the go-to library for building applications on the Interwoven
Stack.
# Migrating from Wallet Widget
Source: https://docs.initia.xyz/interwovenkit/migration
Complete guide for upgrading from the legacy Wallet Widget to InterwovenKit v2
This comprehensive guide will help you migrate from the legacy
`@initia/react-wallet-widget` to the new and improved
`@initia/interwovenkit-react`. InterwovenKit v2 offers better performance,
improved TypeScript support, and a more intuitive API.
<Note>
**Migration Benefits** - No more SSR configuration required - Better
TypeScript support - Improved performance and bundle size - Simplified API
with consistent naming - Enhanced error handling
</Note>
## Step-by-Step Migration
<Steps>
<Step title="Update Package Installation">
Replace the legacy wallet widget package with InterwovenKit.
<CodeGroup>
```bash npm theme={null}
# Remove old package
npm uninstall @initia/react-wallet-widget
# Install new package
npm install @initia/interwovenkit-react
```
```bash yarn theme={null}
# Remove old package
yarn remove @initia/react-wallet-widget
# Install new package
yarn add @initia/interwovenkit-react
```
```bash pnpm theme={null}
# Remove old package
pnpm remove @initia/react-wallet-widget
# Install new package
pnpm add @initia/interwovenkit-react
```
```bash bun theme={null}
# Remove old package
bun remove @initia/react-wallet-widget
# Install new package
bun add @initia/interwovenkit-react
```
</CodeGroup>
<Warning>
Update all imports from `@initia/react-wallet-widget` to `@initia/interwovenkit-react` throughout your codebase.
</Warning>
</Step>
<Step title="Clean Up Legacy Configuration">
Remove SSR-related imports and configuration that are no longer needed.
<AccordionGroup>
<Accordion title="Remove SSR Imports">
```diff theme={null}
- import { ... } from "@initia/react-wallet-widget/ssr"
```
</Accordion>
<Accordion title="Remove Build Configuration">
```diff theme={null}
// next.config.js
module.exports = {
- swcMinify: false,
}
```
</Accordion>
<Accordion title="Remove CDN Scripts">
```diff theme={null}
<!-- Remove any CDN script tags for the wallet widget -->
- <script src="...wallet-widget.js"></script>
```
</Accordion>
</AccordionGroup>
</Step>
<Step title="Install Required Peer Dependencies">
InterwovenKit requires specific peer dependencies for proper functionality.
<CodeGroup>
```bash npm theme={null}
npm install wagmi viem @tanstack/react-query
```
```bash yarn theme={null}
yarn add wagmi viem @tanstack/react-query
```
```bash pnpm theme={null}
pnpm add wagmi viem @tanstack/react-query
```
```bash bun theme={null}
bun add wagmi viem @tanstack/react-query
```
</CodeGroup>
<Info>
These dependencies enable advanced wallet functionality and improved chain interaction capabilities.
</Info>
</Step>
<Step title="Update Provider Configuration">
Replace the legacy provider setup with the new InterwovenKit configuration.
```tsx providers.tsx theme={null}
"use client"
import { PropsWithChildren, useEffect } from "react"
import { createConfig, http, WagmiProvider } from "wagmi"
import { mainnet } from "wagmi/chains"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import {
initiaPrivyWalletConnector,
injectStyles,
InterwovenKitProvider
} from "@initia/interwovenkit-react"
import interwovenKitStyles from "@initia/interwovenkit-react/styles.js"
// Configure Wagmi for wallet connections
const wagmiConfig = createConfig({
connectors: [initiaPrivyWalletConnector],
chains: [mainnet],
transports: { [mainnet.id]: http() },
})
const queryClient = new QueryClient()
export default function Providers({ children }: PropsWithChildren) {
useEffect(() => {
// Inject styles into the shadow DOM used by Initia Wallet
injectStyles(interwovenKitStyles)
}, [])
return (
<QueryClientProvider client={queryClient}>
<WagmiProvider config={wagmiConfig}>
<InterwovenKitProvider defaultChainId="YOUR_CHAIN_ID">
{children}
</InterwovenKitProvider>
</WagmiProvider>
</QueryClientProvider>
)
}
```
<Tip>
The new provider structure separates concerns better and provides more flexibility for wallet configuration.
</Tip>
</Step>
</Steps>
## API Migration Guide
### Provider Configuration Changes
<CodeGroup>
```tsx Legacy (v1) theme={null}
<WalletWidgetProvider chainId="YOUR_CHAIN_ID" />
```
```tsx New (v2) theme={null}
<InterwovenKitProvider defaultChainId="YOUR_CHAIN_ID" />
```
</CodeGroup>
<CodeGroup>
```tsx Legacy (v1) theme={null}
<WalletWidgetProvider customLayer={YOUR_CHAIN} />
```
```tsx New (v2) theme={null}
<InterwovenKitProvider customChain={YOUR_CHAIN} />
```
</CodeGroup>
#### Bridge Configuration Migration
<CodeGroup>
```tsx Legacy (v1) - Provider Level theme={null}
export default function Providers() {
return (
<WalletWidgetProvider
bridgeOptions={{
defaultDstChainId: "YOUR_CHAIN_ID",
defaultDstAssetDenom: "YOUR_DENOM"
}}
/>
)
}
```
```tsx New (v2) - Method Level theme={null}
import { useInterwovenKit } from '@initia/interwovenkit-react'
export default function Home() {
const { openBridge } = useInterwovenKit()
return (
<button
onClick={() =>
openBridge({
dstChainId: 'YOUR_CHAIN_ID',
dstDenom: 'YOUR_DENOM',
})
}
>
Bridge
</button>
)
}
```
</CodeGroup>
<Note>
Bridge configuration has moved from the provider level to individual method
calls, providing more flexibility and better user experience.
</Note>
#### Removed Provider Props
The following props are no longer supported:
```diff theme={null}
- <WalletWidgetProvider additionalWallets={...} />
- <WalletWidgetProvider filterWallet={...} />
```
<Info>
To customize wallet options, use [wagmi
connectors](https://wagmi.sh/react/api/connectors) in your wagmi configuration
instead.
</Info>
### Hook and Method Changes
#### Wallet Connection Interface
<CodeGroup>
```tsx Legacy (v1) theme={null}
import { truncate } from "@initia/utils"
import { useWallet } from "@initia/react-wallet-widget"
export default function WalletButton() {
const { address, onboard, view, bridge, isLoading } = useWallet()
if (!address) { return ( <button onClick={onboard} disabled={isLoading}>
{isLoading ? "Loading..." : "Connect Wallet"} </button> ) }
return ( <div> <button onClick={bridge}>Open Bridge</button>
<button onClick={view}>{truncate(address)}</button> </div> ) }
```
```tsx New (v2) theme={null}
import { truncate } from "@initia/utils"
import { useInterwovenKit } from "@initia/interwovenkit-react"
export default function WalletButton() {
const { address, openConnect, openWallet, openBridge } = useInterwovenKit()
if (!address) {
return <button onClick={openConnect}>Connect Wallet</button>
}
return (
<div>
<button onClick={openBridge}>Open Bridge</button>
<button onClick={openWallet}>{truncate(address)}</button>
</div>
)
}
```
</CodeGroup>
<Warning>
Ensure your entire application is wrapped with `<InterwovenKitProvider>` at the root level for the hooks to function properly.
</Warning>
#### Transaction Handling
<CodeGroup>
```tsx Legacy (v1) theme={null}
import { useWallet } from "@initia/react-wallet-widget"
export default function TransactionComponent() {
const { requestTx } = useWallet()
const handleSubmit = async () => { try { const transactionHash = await
requestTx( { messages: [] }, { chainId: "YOUR_CHAIN_ID" } )
console.log("Transaction submitted:", transactionHash) } catch (error) {
console.error("Transaction failed:", error) } }
return <button onClick={handleSubmit}>Submit Transaction</button> }
```
```tsx New (v2) theme={null}
import { useInterwovenKit } from "@initia/interwovenkit-react"
export default function TransactionComponent() {
const { requestTxBlock } = useInterwovenKit()
const handleSubmit = async () => {
try {
const { transactionHash } = await requestTxBlock({
messages: [],
chainId: "YOUR_CHAIN_ID" // optional, default to InterwovenKit's `defaultChainId`
})
console.log("Transaction confirmed:", transactionHash)
} catch (error) {
console.error("Transaction failed:", error)
}
}
return <button onClick={handleSubmit}>Submit Transaction</button>
}
```
</CodeGroup>
<Tip>
For more granular control over transaction states, use `requestTxSync()` to
get the transaction hash immediately, then `waitForTxConfirmation()` to wait
for blockchain confirmation. See the [useInterwovenKit
reference](./references/hooks/use-interwovenkit#transaction-methods) for
details.
</Tip>
## Advanced Integration
### Working with @initia/initia.js
For complex transaction building, InterwovenKit seamlessly integrates with
`@initia/initia.js`:
```tsx example-usage.tsx theme={null}
import { MsgSend, Msg } from '@initia/initia.js'
import { useInterwovenKit } from '@initia/interwovenkit-react'
// Helper function to convert Initia.js messages to InterwovenKit format
function toEncodeObject(msg: Msg) {
const data = msg.toData()
return {
typeUrl: data['@type'],
value: msg.toProto(),
}
}
export default function SendTransaction() {
const { initiaAddress, requestTxBlock } = useInterwovenKit()
const handleSend = async () => {
// Build messages using initia.js
const msgs = [
MsgSend.fromPartial({
fromAddress: initiaAddress,
toAddress: 'recipient_address_here',
amount: [{ amount: '1000000', denom: 'uinit' }],
}),
]
// Convert to InterwovenKit format
const messages = msgs.map(toEncodeObject)
try {
const { transactionHash } = await requestTxBlock({
messages,
chainId: 'YOUR_CHAIN_ID',
})
console.log('Transfer successful:', transactionHash)
} catch (error) {
console.error('Transfer failed:', error)
}
}
return (
<button onClick={handleSend} disabled={!initiaAddress}>
Send INIT
</button>
)
}
```
## Migration Checklist
<AccordionGroup>
<Accordion title="✅ Package & Dependencies">
* [ ] Uninstalled `@initia/react-wallet-widget`
* [ ] Installed `@initia/interwovenkit-react`
* [ ] Installed peer 프로젝트로 돌아가기