Hooks

@tria-sdk/connect

import * from @tria-sdk/connect;
useTriaConnector
const { globalData } = useTriaConnector({ walletUrl: "https://wallet.tria.so" });
type globalDataType {
    eventType : Object 
}
useAccount
const { account } = useAccount();
export type Account = {
  triaName: string | null;
  evm: {
    address: string;
  };
};

export type useAccountResponse = {
  account: Account | null;
};
useChainName
  1. Pass this to the wallet SDK as selectedChainName

const { chainName } = useChainName();

type useChainResponse = {
  chainName: string | null;
};
useSignMessage
  1. Provide the message and chainName as parameters to the useSignMessage hook.

  2. Execute the signing process by invoking the signMessage function.

  3. Upon completion, you will receive the signature in the returned data.

import { useSignMessage } from "@tria-sdk/connect";

const { 
  data, // signature
  isError, 
  isLoading, 
  isSuccess, 
  signMessage 
} = useSignMessage(
  calldata: SignMessageParams,
  dappDetails?: dappDetails,
  authUrl: string = 'https://auth.tria.so',
  environment: ENV = 'mainnet'
);

type SignMessageParams = {
  message: string;
  chainName: string;
};

type useSignMessageResponse = {
  data: string | null;
  isLoading: boolean;
  isError: boolean;
  isSuccess: boolean;
  signMessage: () => Promise<boolean>;
};
<button onClick={signMessage}>Sign Message</button>
useSendTransaction
  1. Supply the amount, recipient address or tria name, chain name, and token address as parameters to the useSendTransaction hook.

  2. Execute the desired transaction by invoking the sendTransaction function.

  3. Upon completion, you will receive the transaction hash (txHash) and a link to view the transaction on the explorer (viewOnExplorer) in the returned data.

import { useSendTransaction } from "@tria-sdk/connect";

useSendTransaction(
  calldata: SendParams,
  dappDetails?: dappDetails,
  authUrl: string = 'https://auth.tria.so',
  environment: ENV = 'mainnet'
): useSendTxnResponse;

type SendParams = {
  amount: number;
  recepientAddress: string;
  chainName: string;
  tokenAddress?: string;
};

type useSendTxnResponse = {
  data: TxnDataResponse | null;
  isLoading: boolean;
  isError: boolean;
  isSuccess: boolean;
  sendTransaction: Function;
};

type TxnDataResponse = {
  txnId: string;
  viewInExplorer: string;
  wait?: Function;
};

<button onClick={() => sendTransaction()}>send Transaction</button>

Example:

{
	amount: 1, // 1 Matic
	recipientAddress: "lladawn825@tria",
	chainName: "POLYGON",
	tokenAddress: null // null when sending native token
}

{
	amount: 1.5, // 1.5 USDC
	recipientAddress: "lladawn825@tria",
	chainName: "POLYGON",
	tokenAddress: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174" // ERC20 token address
}
useSendNft
useContractRead
  1. Send the chainName and contractDetails

  2. Get the response in data field as expected from contract

Example use case:

  • parse this data suppose fetching price of NFT before minting

  • parse wei to ether to send as value in contractDetails in useContractWrite

useContractWrite
  1. Provide the chain name, payToken, and contractDetails as arguments to the useContractWrite hook.

  2. Invoke the write function to execute the desired action.

  3. you will get the returned txnHash in the data response.

  • Examples

useSwitchChain
Internal hooks

Last updated