dApp Kit
Wallet Hooks
useSignAndExecuteTransactionBlock

useSignAndExecuteTransactionBlock

The useSignAndExecuteTransactionBlock hook can be used to prompt the user to sign and execute a transaction block with their wallet

import {
	ConnectButton,
	useCurrentAccount,
	useSignAndExecuteTransactionBlock,
} from '@mysten/dapp-kit';
import { useState } from 'react';
 
function MyComponent() {
	const { mutate: signAndExecuteTransactionBlock } = useSignAndExecuteTransactionBlock();
	const [digest, setDigest] = useState('');
	const currentAccount = useCurrentAccount();
 
	return (
		<div style={{ padding: 20 }}>
			<ConnectButton />
			{currentAccount && (
				<>
					<div>
						<button
							onClick={() => {
								signAndExecuteTransactionBlock(
									{
										transactionBlock: new TransactionBlock(),
										chain: 'sui:devnet',
									},
									{
										onSuccess: (result) => {
											console.log('executed transaction block', result);
											setDigest(result.digest);
										},
									},
								);
							}}
						>
							Sign and execute transaction block
						</button>
					</div>
					<div>Digest: {digest}</div>
				</>
			)}
		</div>
	);
}

Example

Arguments

  • transactionBlock: The transaction block to sign
  • chain: The chain identifier to sign the transaction block should be signed for
  • requestType: WaitForEffectsCert or WaitForLocalExecution. Determines when the RPC node should return the response. Default to be WaitForLocalExecution
  • options:
    • showBalanceChanges: Whether to show balance_changes. Default to be False
    • showEffects: Whether to show transaction effects. Default to be False
    • showEvents: Whether to show transaction events. Default to be False
    • showInput: Whether to show transaction input data. Default to be False
    • showObjectChanges: Whether to show object_changes. Default to be False
    • showRawInput: Whether to show bcs-encoded transaction input data