Signing and Executing Transactions
Learn how to build, sign, and execute transactions on the Sui blockchain using the dApp Kit.Transaction Workflow
Executing a transaction involves three steps:- Build - Create a transaction block with commands
- Sign - Sign the transaction with the userβs wallet
- Execute - Submit the signed transaction to the blockchain
Transaction Hooks
The dApp Kit provides hooks for transaction operations:| Hook | Purpose |
|---|---|
useSignAndExecuteTransaction | Sign and execute a transaction in one step |
useSignTransaction | Only sign a transaction (doesnβt execute) |
useExecuteTransaction | Execute a pre-signed transaction |
useSignAndExecuteTransaction
The most common hook for executing transactions:Hook Signature
Building Transactions
Use theTransaction class to build programmable transaction blocks:
Transfer SUI
Transfer SUI to another address:Transfer Objects
Transfer any object(s) to another address:Batch Transfers
Transfer to multiple recipients in a single transaction:Merge Coins
Merge multiple coin objects into one:Move Function Calls
Call Move functions from your dApp:Move Call Example: Mint NFT
Transaction Options
Customize transaction execution with options:Error Handling
Handle transaction errors properly:Sign-Only Transactions
Sometimes you need to sign without executing:Execute Pre-Signed Transaction
Execute a transaction that was signed elsewhere:Complete Example: Token Transfer Form
A complete example with form validation and error handling:src/components/TransferForm.tsx
Transaction Gas Configuration
Set custom gas budget and price:Using Transaction Results
Access transaction results for follow-up actions:Best Practices
Always validate user input
Always validate user input
Validate addresses, amounts, and other inputs before building transactions.
Handle all error cases
Handle all error cases
Provide clear error messages for common failures like insufficient balance, user rejection, and network errors.
Show transaction status
Show transaction status
Use loading states and success/error feedback to improve UX.
Link to block explorer
Link to block explorer
After successful transactions, provide a link to view on a block explorer like Suiscan or Suivision.
Test on testnet first
Test on testnet first
Always test transactions on testnet before deploying to mainnet.
Congratulations! π
Youβve completed the Sui dApp Kit workshop! You now know how to:- β Install and configure the Sui SDK and dApp Kit
- β Set up providers for your React app
- β Connect wallets with UI components and hooks
- β Query blockchain data with React hooks
- β Build, sign, and execute transactions