Learning Solana #1: What Is a Transaction?

I’m currently learning Solana dev. For each important topic, I plan on writing a new blog post. Don’t expect these to be particularly organized, linear, or comprehensive! They’re mostly for me.

What’s a transaction?

Transaction: One or more instructions signed by a client using one or more keypairs and executed atomically with only two possible outcomes: success or failure.

Instruction: The smallest contiguous unit of execution logic in a program. An instruction specifies which program it is calling, which accounts it wants to read or modify, and additional data that serves as auxiliary input to the program. A client can include one or multiple instructions in a transaction. An instruction may contain one or more cross-program invocations.

So basically, a transaction contains multiple instructions. And each instruction specifies some code to be run.

Diving Deeper

The diagram below summarizes things better than I could put into words. In short, a transaction consists of an array of signatures and a message. A message consists of a header, an array of addresses, a blockhash, and an array of instructions. Here are a few important things to note.

  • Instructions are executed in order and atomically.
  • Some account addresses don’t require signatures. For example, a program might enforce that only a certain account can increment a counter, in which case the account’s address would require a signature. On the other hand, a program could let anyone read/write anything, in which case no signature would be required. For more on this, see the Anchor docs.
  • A “program id” is the public key of the account containing a program. Basically, it specifies what code should be run.
  • Accounts serve as both “the inputs and outputs of a program.” In other words, on-chain state is represented by accounts. If a program wants to modify on-chain state, it modifies an account (or multiple accounts).
A diagram that summarizes the content of https://docs.solana.com/developing/programming-model/transactions.

Software Engineer. Tweeting @pencilflip. Mediocre boulderer, amateur tennis player, terrible at Avalon. https://www.mattlim.me/