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
Pass this to the wallet SDK as selectedChainName
const { chainName } = useChainName();
type useChainResponse = {
chainName: string | null;
};useSignMessage
Provide the message and chainName as parameters to the
useSignMessagehook.Execute the signing process by invoking the
signMessagefunction.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
Supply the amount, recipient address or tria name, chain name, and token address as parameters to the
useSendTransactionhook.Execute the desired transaction by invoking the
sendTransactionfunction.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
}useContractRead
Send the chainName and contractDetails
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
Provide the chain name, payToken, and contractDetails as arguments to the
useContractWritehook.Invoke the write function to execute the desired action.
you will get the returned txnHash in the data response.
Examples
Last updated