useSignTransaction
Use the useSignTransaction hook to prompt the user to sign a transaction with their wallet.
Live Editor
function UseSignTransactionExample() { const { mutateAsync: signTransaction } = useSignTransaction(); const [signature, setSignature] = useState(''); const client = useIotaClient(); const currentAccount = useCurrentAccount(); return ( <div style={{ padding: 20 }}> {currentAccount && ( <> <div> <button onClick={async () => { const { bytes, signature, reportTransactionEffects } = await signTransaction({ transaction: new Transaction(), }); const executeResult = await client.executeTransactionBlock({ transactionBlock: bytes, signature, options: { showRawEffects: true, }, }); // Always report transaction effects to the wallet after execution reportTransactionEffects(executeResult.rawEffects!); console.log(executeResult); }} > Sign empty transaction </button> </div> <div>Signature: {signature}</div> </> )} </div> ); }
Result
Loading...
Arguments
transaction: The transaction to sign.chain: (optional) The chain identifier the transaction should be signed for.
Returns
signature: The signature of the message, as a Base64-encodedstring.bytes: The serialized transaction bytes, as a Base64-encodedstring.reportTransactionEffects: A function to report the transaction effects to the wallet. This callback should always be invoked after executing the signed transaction. This function accepts therawEffectsreturned from JSON-RPCexecuteTransactionBlockmethod, or theeffects.bcswhen executing with the GraphQL API.