useSignAndExecuteTransaction
Use the useSignAndExecuteTransaction
hook to prompt the user to sign and execute a transaction
block with their wallet.
import { ConnectButton, useCurrentAccount, useSignAndExecuteTransaction } from '@mysten/dapp-kit';
import { useState } from 'react';
function MyComponent() {
const { mutate: signAndExecuteTransaction } = useSignAndExecuteTransaction();
const [digest, setDigest] = useState('');
const currentAccount = useCurrentAccount();
return (
<div style={{ padding: 20 }}>
<ConnectButton />
{currentAccount && (
<>
<div>
<button
onClick={() => {
signAndExecuteTransaction(
{
transaction: new Transaction(),
chain: 'sui:devnet',
},
{
onSuccess: (result) => {
console.log('executed transaction', result);
setDigest(result.digest);
},
},
);
}}
>
Sign and execute transaction
</button>
</div>
<div>Digest: {digest}</div>
</>
)}
</div>
);
}
Example
Arguments
transaction
: The transaction to sign and execute.chain
: (optional) The chain identifier the transaction should be signed for.
In addition to these options, you can also pass any options that the SuiClient.signAndExecuteTransaction method accepts.