Executing Transactions
Simulate, execute, and wait for transactions with any Sui client
Executing a transaction is a client operation, and every client exposes the same four methods for it. Building transactions is covered in Building transactions, and the ways to obtain a signature (keypairs, wallets, sponsorship) in Signing and execution.
signAndExecuteTransaction
Signs with the given signer and executes, in one call:
import { SuiGrpcClient } from '@mysten/sui/grpc';
const client = new SuiGrpcClient({
network: 'mainnet',
baseUrl: 'https://fullnode.mainnet.sui.io:443',
});
const result = await client.signAndExecuteTransaction({
transaction: tx,
signer: keypair,
include: { effects: true },
});The signer can be any Signer, such as a keypair or a KMS or Ledger signer. Pass
additionalSignatures for transactions needing more than one, such as a sponsored transaction the
sponsor has already signed.
executeTransaction
When you already have signed bytes, execute them directly:
const result = await client.executeTransaction({
transaction: bytes, // Uint8Array
signatures: [signature], // string[]
include: { effects: true, events: true },
});Both methods return a discriminated union rather than throwing on failure: a transaction that
executed but aborted onchain comes back as FailedTransaction.
const transaction = result.Transaction ?? result.FailedTransaction;
console.log(transaction.digest, transaction.status.success);A resolved promise means the network executed the transaction, which is not the same as it having succeeded. See checking success or failure for handling both outcomes.
Include options
Execution, simulation, and getTransaction share one set of
include options. Everything is off by default, and a field that you did not request is typed
undefined:
| Option | Description |
|---|---|
effects | Execution effects: created, mutated, and deleted objects, gas used |
events | Move events emitted during execution |
transaction | Ledger data: sender, gas config, expiration, and transaction kind |
balanceChanges | Balance changes for each affected address and coin type |
objectTypes | Map of object ID to type for all changed objects |
bcs | Raw BCS-encoded transaction bytes |
Transaction data
include: { transaction: true } returns transaction data with sender, gasData, expiration,
inputs, commands, and kind. inputs and commands hold the inputs and commands of a
programmable or programmable system transaction, and are empty for every other kind. Use
kind.$kind to identify the transaction type and access its payload:
const result = await client.getTransaction({
digest,
include: { transaction: true },
});
const { transaction: data } = result.Transaction ?? result.FailedTransaction;
switch (data.kind.$kind) {
case 'ProgrammableTransaction':
console.log(data.kind.ProgrammableTransaction.inputs);
console.log(data.kind.ProgrammableTransaction.commands);
break;
case 'Genesis':
console.log(data.kind.Genesis.objects.length);
break;
case 'Unknown':
console.log('Transaction kind not supported by this SDK version');
break;
default:
console.log('System transaction:', data.kind.$kind);
}ProgrammableTransaction and ProgrammableSystemTransaction contain inputs and commands. Other
kinds, such as Genesis, ChangeEpoch, and RandomnessStateUpdate, have their own payloads.
If the SDK does not recognize a transaction's kind, or cannot map one of its inputs or commands,
kind is { $kind: 'Unknown', Unknown: true } and inputs and commands are empty; sender,
gasData, and expiration are still set. Upgrade the SDK to read kinds added by newer network
versions.
To decode transaction bytes yourself, use parseTransactionBcs from @mysten/sui/client. It
returns the same shape, but throws on bytes that use a variant the SDK does not know.
waitForTransaction
Reads are served from indexed state, which trails execution slightly. Wait before reading a transaction's effects back, or before submitting a transaction that depends on objects it touched:
const result = await client.signAndExecuteTransaction({ transaction: tx, signer: keypair });
await client.waitForTransaction({ result });
// Reads now reflect the transaction's effects
const { balance } = await client.getBalance({ owner: myAddress });It also accepts a digest instead of a result, along with timeout and a pollSchedule array of
backoff delays.
waitForTransaction resolves once the transaction can be fetched from the client's server; reads of
your own writes through that client are then expected to see it.
simulateTransaction
Dry-run a transaction without executing it, to estimate gas, inspect return values, or validate it before asking anyone to sign:
const result = await client.simulateTransaction({
transaction: tx,
include: {
effects: true,
balanceChanges: true,
commandResults: true,
},
});Simulation takes the same include options plus commandResults, which returns each command's return
values and mutated references as BCS-encoded bytes for you to decode with the BCS library.
Two further options change how the node runs the simulation:
| Option | Effect |
|---|---|
checksEnabled | Set false to skip transaction validation, so non-public and non-entry functions can be inspected. Defaults to true |
doGasSelection | Overrides whether the node selects real gas. Defaults to true only when gas payment is [] |
When the node does not select gas, a transaction with no gas coins is simulated with a mocked gas
coin unless the sender's address balance covers the budget. The mocked coin also funds anything
drawn from tx.gas. The result validates the transaction and estimates gas, but is not a preview of
what the sender would spend. To simulate with the sender's real gas, set gas coins on the
transaction, or set an empty gas payment and let the node select gas. The result's
gasPaymentMocked field reports whether gas was mocked.