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

Building Offline

To build a transaction offline (with no client required), you need to fully define all of your inputs, gas configuration, and expiration.

Required Configuration

When building offline, you must set the following:

  • Sender address - The address that will execute the transaction
  • Gas price - The price per gas unit (can be obtained from the network beforehand)
  • Gas budget - The maximum gas to spend on this transaction
  • Gas payment - One or more coin object references to use for gas, or an empty array for Address Balances
  • Expiration - Only needed when using address balances for gas
import { Transaction } from '@mysten/sui/transactions';

const { referenceGasPrice } = await client.getReferenceGasPrice();

const tx = new Transaction();

tx.setSender('0x<your-address>');
tx.setGasPrice(referenceGasPrice);
tx.setGasBudget(50_000_000);
tx.setGasPayment([
	{
		objectId: '0x<gas-coin-object-id>',
		version: '<object-version>',
		digest: '<object-digest>',
	},
]);

// Build the transaction without a client
const bytes = await tx.build();

Object References

For objects used in your transaction, you must provide full object references using the Inputs helper:

import { Inputs } from '@mysten/sui/transactions';

// For owned or immutable objects
tx.object(
	Inputs.ObjectRef({
		objectId: '0x<object-id>',
		version: '<object-version>',
		digest: '<object-digest>',
	}),
);

// For shared objects
tx.object(
	Inputs.SharedObjectRef({
		objectId: '0x<object-id>',
		initialSharedVersion: '<initial-shared-version>',
		mutable: true,
	}),
);

// For receiving objects (objects being received by another object)
tx.object(
	Inputs.ReceivingRef({
		objectId: '0x<object-id>',
		version: '<object-version>',
		digest: '<object-digest>',
	}),
);

On this page