Kit
Functions

useSignAndSendTransaction

Call Signature

useSignAndSendTransaction<TWalletAccount>(uiWalletAccount, chain): (input) => Promise<SolanaSignAndSendTransactionOutput>

Use this to get a function capable of signing a serialized transaction with the private key of a UiWalletAccount and sending it to the network for processing.

Type Parameters

Type Parameter
TWalletAccount extends UiWalletAccount

Parameters

ParameterTypeDescription
uiWalletAccountTWalletAccount-
chainOnlySolanaChains<TWalletAccount["chains"]>The identifier of the chain the transaction is destined for. Wallets may use this to simulate the transaction for the user.

Returns

(input): Promise<SolanaSignAndSendTransactionOutput>

Parameters

ParameterType
inputInput

Returns

Promise<SolanaSignAndSendTransactionOutput>

Example

import { getBase58Decoder } from '@solana/codecs-strings';
import { useSignAndSendTransaction } from '@solana/react';
 
function SignAndSendTransactionButton({ account, transactionBytes }) {
    const signAndSendTransaction = useSignAndSendTransaction(account, 'solana:devnet');
    return (
        <button
            onClick={async () => {
                try {
                    const { signature } = await signAndSendTransaction({
                        transaction: transactionBytes,
                    });
                    const base58TransactionSignature = getBase58Decoder().decode(signature);
                    window.alert(
                        `View transaction: https://explorer.solana.com/tx/${base58TransactionSignature}?cluster=devnet`,
                    );
                } catch (e) {
                    console.error('Failed to send transaction', e);
                }
            }}
        >
            Sign and Send Transaction
        </button>
    );
}

Call Signature

useSignAndSendTransaction<TWalletAccount>(uiWalletAccount, chain): (input) => Promise<SolanaSignAndSendTransactionOutput>

Use this to get a function capable of signing a serialized transaction with the private key of a UiWalletAccount and sending it to the network for processing.

Type Parameters

Type Parameter
TWalletAccount extends UiWalletAccount

Parameters

ParameterTypeDescription
uiWalletAccountTWalletAccount-
chain`solana:${string}`The identifier of the chain the transaction is destined for. Wallets may use this to simulate the transaction for the user.

Returns

(input): Promise<SolanaSignAndSendTransactionOutput>

Parameters

ParameterType
inputInput

Returns

Promise<SolanaSignAndSendTransactionOutput>

Example

import { getBase58Decoder } from '@solana/codecs-strings';
import { useSignAndSendTransaction } from '@solana/react';
 
function SignAndSendTransactionButton({ account, transactionBytes }) {
    const signAndSendTransaction = useSignAndSendTransaction(account, 'solana:devnet');
    return (
        <button
            onClick={async () => {
                try {
                    const { signature } = await signAndSendTransaction({
                        transaction: transactionBytes,
                    });
                    const base58TransactionSignature = getBase58Decoder().decode(signature);
                    window.alert(
                        `View transaction: https://explorer.solana.com/tx/${base58TransactionSignature}?cluster=devnet`,
                    );
                } catch (e) {
                    console.error('Failed to send transaction', e);
                }
            }}
        >
            Sign and Send Transaction
        </button>
    );
}

On this page