On this page
Transactions
The signing examples below use connectSuiAccount() from Getting Started. It returns a Wallet Standard account and its active chain. The examples use @mysten/[email protected]. Even the legacy *TransactionBlock methods now declare Transaction inputs in @mysten/[email protected].
Request permission before signing, select a connected account, and read the active chain. These examples use @mysten/[email protected], matching @mysten/[email protected] accepted by the current provider.
Learn how to sign and execute transactions on Sui.
Initialize the account context before the following examples:
const { account, chain } = await connectSuiAccount()Sign and Execute Transaction Block
The current injected provider does not forward options in signAndExecuteTransactionBlock. Query the returned digest with a Sui client on the same chain to request effects, events, or object changes.
import { Transaction } from '@mysten/sui/transactions'
// Create transaction block
const txb = new Transaction()
// Add a transfer
txb.transferObjects(
[txb.object('0xobject_id')],
txb.pure.address('RECIPIENT_SUI_ADDRESS')
)
// Or send SUI
const [coin] = txb.splitCoins(txb.gas, [txb.pure.u64(1000000000)]) // 1 SUI
txb.transferObjects([coin], txb.pure.address('RECIPIENT_SUI_ADDRESS'))
// Sign and execute
const result = await provider.signAndExecuteTransactionBlock({
account,
chain,
transactionBlock: txb,
})
console.log({
digest: result.digest,
})Sign Transaction Block (Without Executing)
const txb = new Transaction()
// ... build transaction
const signedTxb = await provider.signTransactionBlock({
account,
chain,
transactionBlock: txb,
})
console.log({
transactionBlockBytes: signedTxb.transactionBlockBytes,
signature: signedTxb.signature,
})
// Execute later using Sui SDK
// const result = await suiClient.executeTransactionBlock({
// transactionBlock: signedTxb.transactionBlockBytes,
// signature: signedTxb.signature,
// })Sign and Execute Transaction (New API)
// Using the newer signAndExecuteTransaction method
import { Transaction } from '@mysten/sui/transactions'
const transaction = new Transaction()
const [coin] = transaction.splitCoins(transaction.gas, [transaction.pure.u64(100000000)])
transaction.transferObjects([coin], transaction.pure.address('RECIPIENT_SUI_ADDRESS'))
const result = await provider.signAndExecuteTransaction({
account,
chain,
transaction,
})Sign Transaction (New API)
const signedTxn = await provider.signTransaction({
account,
chain,
transaction,
})Smart Contract Interaction
Move Call
const txb = new Transaction()
// Call a Move function
txb.moveCall({
target: '0xpackage::module::function',
arguments: [
txb.pure.string('arg1'),
txb.object('0xobject_id'),
],
typeArguments: ['0x2::sui::SUI'],
})
const result = await provider.signAndExecuteTransactionBlock({
account,
chain,
transactionBlock: txb,
})Publish Package
const txb = new Transaction()
const [upgradeCap] = txb.publish({
modules: compiledModules,
dependencies: [
'0x1', // Move stdlib
'0x2', // Sui framework
],
})
txb.transferObjects([upgradeCap], txb.pure.address(account.address))
const result = await provider.signAndExecuteTransactionBlock({
account,
chain,
transactionBlock: txb,
})Using with Sui SDK
import { SuiClient } from '@mysten/sui/client'
const client = new SuiClient({ url: 'https://fullnode.mainnet.sui.io' })
// Get balance
const balance = await client.getBalance({
owner: accountAddress,
})
// Get objects
const objects = await client.getOwnedObjects({
owner: accountAddress,
})
// Get transaction
const txn = await client.getTransactionBlock({
digest: txDigest,
options: { showEffects: true },
})