llms.txt
@mysten/sui v2.0 and a new dApp Kit are here! Check out the migration guide
Mysten Labs SDKs
Actions

Sign and Execute Transaction

Sign and execute a transaction on the Sui network using the connected wallet.

The signAndExecuteTransaction action prompts the connected wallet to sign and immediately execute a transaction on the Sui network. This is the most common way to execute transactions in your app.

Usage

import { createDAppKit } from '@mysten/dapp-kit-core';
import { Transaction, coinWithBalance } from '@mysten/sui/transactions';

const dAppKit = createDAppKit({
	/* config */
});

const tx = new Transaction();
// No need to manually set sender - it's done automatically
tx.transferObjects([coinWithBalance({ balance: 123 })], '0xrecipient...');

const result = await dAppKit.signAndExecuteTransaction({
	transaction: tx,
});

if (result.FailedTransaction) {
	throw new Error(`Transaction failed: ${result.FailedTransaction.status.error?.message}`);
}

console.log('Transaction digest:', result.Transaction.digest);

Parameters

  • transaction: Transaction | string: The transaction to sign and execute. Can be either a Transaction instance or base64-encoded bcs bytes for the transaction.
  • account (optional): UiWalletAccount: The account to sign with. Defaults to the currently connected account. Must belong to the connected wallet, otherwise a WalletAccountNotFoundError is thrown. Lets you sign with a specific account without changing the selected account via switchAccount.
  • network (optional): The network to sign and execute against (a configured network identifier such as 'mainnet'). Defaults to the active network. The chain and the client used to build the transaction are derived from it, so you can target a network without changing the active network via switchNetwork. Throws a ChainNotSupportedError if the signing account does not support the network.
  • signal (optional): AbortSignal: An abort signal to cancel the transaction request.

Return value

Returns a Promise that resolves to a TransactionResult discriminated union:

type TransactionResult =
	| { $kind: 'Transaction'; Transaction: Transaction }
	| { $kind: 'FailedTransaction'; FailedTransaction: Transaction };

The Transaction object contains:

  • digest: string: The transaction digest (unique identifier for the executed transaction)
  • signatures: string[]: The signatures as base64-encoded strings
  • epoch: string | null: The epoch in which the transaction was executed
  • status: ExecutionStatus: The execution status with success: boolean and error: string | null
  • effects: TransactionEffects | null: The parsed transaction effects (may be null if effects parsing fails for unknown effect versions)
  • transaction: TransactionData: The parsed transaction data
const result = await dAppKit.signAndExecuteTransaction({ transaction });

if (result.FailedTransaction) {
	console.error('Transaction failed:', result.FailedTransaction.status.error?.message);
	return;
}

// Access the successful transaction results
const tx = result.Transaction;
console.log('Digest:', tx.digest);
console.log('Signatures:', tx.signatures);
console.log('Epoch:', tx.epoch);

Transaction building

When passing a Transaction instance, the action automatically:

  1. Sets the sender address if not already set
  2. Builds the transaction using the current network's client
  3. Converts it to the appropriate format for the wallet
  4. Submits the transaction to the network

Wallet compatibility

  • The action transparently handles both sui:signAndExecuteTransaction and sui:signAndExecuteTransactionBlock wallet-standard features
  • The wallet handles network submission and response
  • Some wallets (Enoki, Enoki Connect, and WalletConnect) might use the dApp Kit client and execute transactions within the application as an implementation detail
// The action automatically detects and uses the appropriate method
// No special configuration needed
const result = await dAppKit.signAndExecuteTransaction({
	transaction: tx,
});

On this page