Transactions: At Stellar Core
Last updated
Last updated
To interact with the Stellar Network and perform any action youโll be using Transactions. Theyโre built by a set of elements weโll see shortly, but its most important component is Operations. When working with Stellar Classic youโll bundle a set of operations into a Transaction to later submit them to the network and actually perform them. When building a Smart Contract transaction youโll only be able to have a single operation per transaction.
Stellar encodes transactions using a standardized protocol called External Data Representation (XDR). It is not human-readable, but you can parse it as a JSON using Stellar SDK or through its XDR Viewer. Letโs check some of itโs core features:
Transactions are atomic, which means all of the operations contained in it should pass for the transaction to be applied. If one of them fails for any reason the whole transaction will be canceled. This also means youโll have to keep in mind the order in which you set your operations, as perhaps some of them rely on others before.
An account can only perform one transaction at once, but each transaction can contain up to 100 operations.
Operations are always executed for the source account of the transaction unless an operation override is defined.
Every transaction must be signed with the public keyโs associated secret key to be submitted to the ledger. Once it has a signature(s) added it is called a transaction envelope. Some of them may need more than one signature. You can learn more about that here.
Weโve already talked about how operations are the main component of a transaction, but it must include a couple more elements:
A source account, which will be the account where the operations will be executed.
A fee, which can be set to a minimum or can be set dynamically according to fee prices at the moment. You can check the average Stellar fee at the moment your transaction will be submitted here . Keep in mind that while in the testnet your transactions will almost always pass with a low fee on the mainnet youโll probably need a higher fee for them to actually be applied.
The list of operations it will be performing. You can check all of the operations available and its requirements here.
A timeout, it will be the max time in which your operation can be performed. If its too low it could mean a transaction failure.
You can see these below implementing Stellar SDK:
Once youโve checked all of these items to build your transaction the ledger will validate your transaction -and all of its operations- to validate it. Letโs check those validations:
Time bounds: Time bounds are an optional UNIX timestamp (in seconds), determined by ledger time, of a lower and upper bound of when a transaction will be valid. If a transaction is submitted too early or too late, it will fail to make it into the transaction set.
Sequence number: The sequence number must be one greater than the sequence number stored in the source account entry when the transaction is applied unless sequence number preconditions are set.
Signers: The transaction must include signatures from all the accounts to which operations will be performed
Operations: All of the operations included must be well-formed, including all of its required parameters in the correct formats. You must not include deprecated operations.
Source account: It must already exist on the ledger and have funds to perform the operations and pay the required fee.
Fee: The fee must be greater than or equal to the network minimum fee for the number of operations submitted as part of the transaction.
Memo: If it includes a memo it must be a valid type and adhere to the correct formatting
Transactions are the backbone of interacting with the Stellar Network, encapsulating operations to perform various actions. They must meet strict validity requirements, including proper sequence numbers, signatures, fees, and source account conditions, to ensure reliability and security. Understanding the transaction structure and adhering to its requirements is crucial for effectively leveraging the Stellar ecosystem.