@initia/react-wallet-widget
: A React component that enables users to connect their Initia Wallet as well as other wallets.@initia/initia.js
: A JavaScript library to interact with the Initia blockchain and minitias, including querying user balances and signing and sending transactions@cosmjs/proto-signing
: A JavaScript library that allows us to sign encode Cosmos SDK messages for signing.WalletWidgetProvider
to our project. This will allow us to use the useWallet
hook to interact with the wallet. To do so, we need to import the WalletWidgetProvider
from @initia/react-wallet-widget
and wrap the children
component in src/layout.tsx
with it.
chainId
to any chain that is in the initia-registry.
WalletWidgetProvider
in place, we can use the useWallet
hook to interact with the wallet. We will do this by modifying src/page.tsx
.
First, we declare use client
at the top of the file and import the necessary libraries and hooks.
useAddress
: A hook that returns the address of the connected wallet.useWallet
: A hook that returns the wallet object.MsgSend
: A message type that is used to send tokens from one wallet to another.EncodeObject
: A type that is used to encode Cosmos SDK messages for signing.Msg
: A type that is used to represent a Cosmos SDK message.useState
: A hook that allows us to use state in our component.Msg
type into an array of EncodeObject
types.
address
: The address of the connected wallet.onboard
: The wallet object.view
: A function that allows us to view the wallet.requestTx
: A function that allows us to request a transaction from the wallet.isLoading
: A state variable that indicates whether the transaction is being requested.transactionHash
: A state variable that stores the transaction hash.send
function that will send a transaction to the wallet. The function will check if the wallet is connected, and if it is, it will request a transaction to send 1000000 uinit
(1 INIT) from the wallet to itself.
src/layout.tsx
and src/page.tsx
file should look like the following:
bun run dev
and navigate to http://localhost:3000
to see the project in action. If everything is working correctly, you should see a an interface similar to the following: