Programmable Transaction Blocks (PTBs) in Sui give developers a very powerful programming tool not available on other blockchains. The ability to chain multiple transactions together in a single executable may be taken for granted in the wider world of software engineering, but on blockchains it represents a fundamental leap forward.
The relatively short history of blockchain development focused on transaction processing, a difficult challenge on a decentralized network where independent operators must process each transaction and come to consensus on whether it's valid. With a well-understood transaction processing mechanism in place, Sui implemented PTBs, letting developers combine a series of actions touching multiple objects in a single transaction.
PTBs move the blockchain world from simple transactions that can only execute a single action to transactions that contain many actions, allowing for truly sophisticated and complex apps. PTBs let apps on Sui process a series of inputs, lines of executable code, and objects before sending the entire block for verification as a transaction on the network.
Conventional blockchains process each transaction submitted to the network individually, typically aiming for veracity and efficiency. While this model makes sense in systems that focus on exchanges between two parties, it seems simplistic when compared to modern software engineering principles. In engineering terms, it would be like having each app only run a single executable code line. Multiple apps would need to accomplish what we think of as simple tasks today, such as editing and saving a digital image in a photo editing app.
The PTB primitive in Sui lets developers write code that can access any public on-chain Move function across all smart contracts. A PTB can take multiple inputs and affect multiple objects over the course of its execution. A car racing game app could, for example, use a PTB to take steering and acceleration inputs from the user to their car, process more inputs from a physics model, and register a collision with a tirewall, including altering the objects that make up the car to reflect damage.
Describing PTBs, Mysten Labs CTO Sam Blackshear said, "...in the simple case of sending 100 transactions to mint 100 NFTs you can send one transaction that mints 100 NFTs. And that costs about the same as it would to mint one NFT."
PTBs support up to 1,024 individual transactions, allowing for apps that can exhibit complex and sophisticated functionality. And instead of requiring the network to process each transaction individually, they all process as one large transaction. Developers will use the
TransactionBlock primitive to build a PTB.
If one transaction in a PTB fails, the entire PTB will fail. This design prevents apps from executing incomplete actions.
As engineers find smarter, more efficient ways of building things, software programming tends to evolve. The blockchain space began relatively recently as a new domain, requiring its own evolution around programming for distributed systems. However, the wider world of software engineering provides many examples of best practices and innovation that could be applied to blockchain.
Although Sui's development was rooted in the blockchain domain, it takes existing examples from other software domains. PTBs are one way that Sui gives developers the unbounded expressivity and efficiency they may be accustomed to from other platforms.