Learn

Smart Contract Basics

The idea of smart contracts was originally proposed by back in the early 1990s as a: “set of promises, specified in digital form, including protocols within which the parties perform on these promises.”
Years later, this proposal became a reality with the help of blockchain technology. Smart contracts are a key component of many blockchain-based ecosystems. They can automate complex processes, enforce agreements, and manage digital assets in a trustless system. Smart contracts have the potential to transform the way businesses, applications, and individuals interact and exchange value across various platforms and industries. 

While Stellar didn’t initially have smart contract capabilities, this decision was officially reconsidered in 2022 as the technology advanced and real-world use cases became apparent. Stellar’s native smart contracts platform is called Soroban𝕴, which is built to be scalable and developer-friendly.

What is a smart contract?

A smart contract is a self-executing program that is run and stored on a blockchain network. Smart contracts execute automatically when predefined terms and conditions are met without the need for intermediaries such as banks, lawyers, or voting authorities. They can also automate complex workflows by triggering the next action when certain conditions are met. Smart contracts can operate independently, but many decentralized applications (dApps) implement several contracts that work together to achieve certain functionalities.

What are the benefits of smart contracts?

Time and cost efficiency

Smart contracts are digital and automated, which streamlines processes and saves time and money. Without the need for intermediaries, there’s no paperwork, no back and forth between parties, and less chance for human error and manipulation.

Trust and transparency

Smart contracts are transparent due to their underlying blockchain technology. Once a smart contract is deployed on the blockchain, its code and associated transactions are publicly accessible and cannot be altered. Participants are able to independently verify a contract’s terms, behavior, and outcome.

Security

Smart contracts are encrypted and leverage cryptographic security techniques, such as digital signatures and hashing, to protect data integrity and authenticate participants. Once a smart contract is deployed on a blockchain, its code and transactions are immutable.

Permissionless

Stellar and Soroban are open-source, and anyone can write a smart contract and deploy it to the Stellar network as long as they know how to code in a supported smart contract language.

How do smart contracts work?

Write 

The developer writes the smart contract using a programming language supported by the platform. Writing the contract consists of defining the contract’s terms and conditions, functions, and rules for execution.

Test 

Once the contract is written, the developer tests the smart contract in a local or testnet environment to ensure everything works correctly.

Deploy

Next, the developer deploys the smart contract to the blockchain’s mainnet by submitting a transaction with the compiled contract code.

Invoke 

When the contract is deployed, others can interact with it by sending transactions that invoke its functions. These interactions trigger the contract’s execution, and the blockchain network validates and records the resulting state changes.

What are some common applications for smart contracts?

Voting systems and DAO governance

Many current voting systems are susceptible to voter manipulation and fraud. With smart contracts, votes would be recorded on the blockchain ledger, which is unchangeable and irreversible. ‍Smart contract-controlled voting systems also play a big part in decentralized autonomous organization(DAO) governance.

Decentralized finance (DeFi)

DeFi applications provide a more trustless, immutable, and transparent alternative to traditional financial services, such as lending, borrowing, trading, and asset management. dApps reduce or eliminate the need to rely on third-party intermediaries and offer consistent functionality, which opens up financial opportunities to people worldwide. 

NFTs and gaming

Smart contracts are used in gaming to allow the creation, ownership, and trading of in-game assets, often as non-fungible tokens (NFTs). They facilitate decentralized marketplaces, manage transfers between players, and maintain transparent ownership records. They can also automate rewards distribution and implement royalty systems for creators.

Supply chain management

Traditional supply chains use paper-based systems that are time-consuming and prone to mistakes. With a smart contract-powered end-to-end supply chain, no daily management or auditing would be needed. Smart contracts would be able to track and verify the movement of goods, ensuring product authenticity and streamlining logistics. 

Can you use smart contracts on Stellar?

Yes! ♏Smart contracts are usable on the Stellar network with Soroban, Stellar’s native smart contracts platform. 

Soroban is an additive feature that is integrated into the existing Stellar blockchain and is able to interact with Stellar accounts and assets. Soroban is currently live on Futurenet, a shared test network with Mainnet launch happening later in 2023. 

Get started with Soroban now by accessing our Soroban documentation.

Learn