Signing and Sending Transactions
Transactions in Sui represent calls to specific functionality (like calling a smart contract function) that execute on inputs to define the result of the transaction.
Inputs can either be an object reference (either to an owned object, an immutable object, or a shared object), or an encoded value (for example, a vector of bytes used as an argument to a Move call). After a transaction is constructed, usually through using programmable transaction blocks (PTBs), the user signs the transaction and submits it to be executed on chain.
The signature is provided with the private key owned by the wallet, and its public key must be consistent with the transaction sender's Sui address.
Sui uses a SuiKeyPair
to produce the signature, which commits to the Blake2b hash digest of the intent message (intent || bcs bytes of tx_data
). The signature schemes currently supported are Ed25519 Pure
, ECDSA Secp256k1
, ECDSA Secp256r1
, Multisig
, and zkLogin
.
You can instantiate Ed25519 Pure
, ECDSA Secp256k1
, and ECDSA Secp256r1
using SuiKeyPair
and use it to sign transactions. Note that this guide does not apply to Multisig
and zkLogin
, please refer to their own pages (Multisig and zkLogin respectively) for instructions.
With a signature and the transaction bytes, a transaction can be submitted to be executed.
Workflow
The following high-level process describes the overall workflow for constructing, signing and executing an on-chain transaction:
- Construct the transaction data by creating a
Transaction
where multiple transactions are chained. See Building Programmable Transaction Blocks for more information. - The SDK's built-in gas estimation and coin selection picks the gas coin.
- Sign the transaction to generate a signature.
- Submit the
Transaction
and its signature for on-chain execution.
If you want to use a specific gas coin, first find the gas coin object ID to be used to pay for gas, and explicitly use that in the PTB. If there is no gas coin object, use the splitCoin transaction to create a gas coin object. The split coin transaction should be the first transaction call in the PTB.