useWormhole
This hook is used to provide the Wormhole-sdk-ts interface in React Hooks. And it can be used in both Workhole kit and Wormhole Kit Core.
Usage
You can export and use these properties.
typescript
import {
useWormhole,
} from '@zktx.io/wormhole-kit-core';
export const SomeComponent = () => {
const {
supportChains,
getSymbol,
getBalance,
buildTransferTx,
buildRedeemTx,
} = useSuiProvider();
return <>...</>;
}
Properties
supportChains
This function returns the chain set on the provider.
typescript
/*
// packages/wormhole-kit-core/src/provider/types.ts
import type { Chain } from '@wormhole-foundation/sdk-connect';
*/
() => Chain[]
getSymbol
This function returns the token's symbol.
typescript
/*
// packages/wormhole-kit-core/src/provider/types.ts
import type { Chain } from '@wormhole-foundation/sdk-connect';
export interface IReqTokenInfo {
chain: Chain;
token?: string;
}
*/
(req: IReqTokenInfo) => string;
getBalance
This function returns the token's balance.
typescript
/*
// packages/wormhole-kit-core/src/provider/types.ts
import type { Chain } from '@wormhole-foundation/sdk-connect';
export interface IReqBalance {
chain: Chain;
// wallet address
address: string;
// If token is undefined, the balance of the native token is returned.
token?: string;
}
export interface IResBalance {
fValue?: number;
value: string;
}
*/
async (req: IReqBalance) => Promise<IResBalance>;
buildTransferTx
This function returns the transfer transaction object.
typescript
/*
// packages/wormhole-kit-core/src/provider/types.ts
import type { Chain } from '@wormhole-foundation/sdk-connect';
export interface IUniversalAccount {
chain: Chain;
address: string;
}
export interface IReqTransferTx {
sender: IUniversalAccount;
receiver: IUniversalAccount;
token?: string;
amount: string;
}
export interface IResTransaction {
error?: string;
unsignedTxs: Array<IUnsignedTx>;
}
*/
async (req: IReqTransferTx) => Promise<IResTransaction>;
buildRedeemTx
This function returns the redeem transaction object.
typescript
/*
// packages/wormhole-kit-core/src/provider/types.ts
import type { Chain } from '@wormhole-foundation/sdk-connect';
export interface IReqRedeemTx {
source: Chain;
txHash: string;
receiver: IUniversalAccount;
}
export interface IResTransaction {
error?: string;
unsignedTxs: Array<IUnsignedTx>;
}
*/
async (req: { source: Chain; txHash: string; receiver: IUniversalAccount }) =>
Promise<IResTransaction>;