Learn

Smart Contract Building Blocks

A smart contracts platform allows developers to write code to a blockchain, but that alone is not sufficient to build full-fledged products and services that support real, sustainable smart contract use cases that execute safely and efficiently.

Background

Smart contract building blocks

A smart contracts platform allows developers to write code to a blockchain, but that alone is not sufficient to build full-fledged products and services that support real, sustainable smart contract use cases that execute safely and efficiently. Building out those end-to-end use cases requires interlocking building blocks that work in combination to effectively control and respond to actions and events. Even a technically powerful smart contract platform like Soroban doesn’t really function without them: it’s like a house wired for electricity without sockets, light bulbs, or appliances plugged in. The importance of smart contract building blocks is fundamentally about turning on the platform: adding in the sockets, screwing in the light bulbs, and plugging in the appliances until the whole house is glowing and humming.

But not only that: blockchain is unique in that applications share state, or a single database, which presents challenges but also enables previously unseen levels of compatibility and interoperability. The interrelatedness of components in the ecosystem means that builders can be massively productive by utilizing the work of others. Soroban's architecture and integration with the Stellar network will enhance this interoperability, allowing developers to create more complex and interconnected applications.

Essential building blocks that power a smart contract ecosystem include:



About

Financial building blocks

As a core use case of smart contracts, decentralized finance (DeFi) leverages blockchain and smart contract technology to provide financial services to users around the world without the need for banks or traditional financial institutions. Yet for smart contracts to enable these DeFi capabilities, they need to offer end consumers the ability to do something with the assets once they’re on-chain. As rules and standards that govern decentralized finance applications, DeFi protocols are crucial to the ecosystem because they enhance access, increase trustlessness, and remove mediating parties, giving users immediate control over their own funds. Essential financial building blocks that offer these DeFi capabilities include:

  • Swap functionality enabled by token swap dApps to facilitate efficient asset exchange, and Automated Market Makers (AMMs) to provide liquidity for a range of digital assets. As the DeFi protocol that powers decentralized exchanges, an AMM provides the necessary liquidity to enable swaps and exchanges across currencies and between users directly, without intermediaries like centralized exchanges or financial institutions. In addition to liquidity pools consisting of two or more assets to swap between, AMMs include multiple pricing curve options to support different types of assets, and tokenized pool deposits, which are transferable and depositable into other smart contracts.
  • Lending and borrowing markets that allow any user to borrow or lend digital assets via decentralized platforms governed by smart contracts that determine interest rates, amounts, repayment terms, and loan expiration dates. These markets allow users to borrow another asset against collateral, to post that collateral by supplying it to a smart contract, and to deposit and lend assets to earn yield. Lending and borrowing markets are often designed to be composable with other smart contracts such that they can be used as yield and credit facilities for other services built on the network.

Soroban's support for decentralized finance (DeFi) and its compatibility with various DeFi protocols will make it a powerful platform for building financial applications that leverage these essential building blocks.

About

Data access

While the above protocols and financial building blocks provide the functionality for different types of financial actions and events, they often rely on real-world conditions to execute. Lending and borrowing protocols might need up-to-date exchange or interest rates in order for the smart contracts that leverage them to run. AMMs might need price information to stay updated on market conditions in order to stabilize their liquidity pools and keep them adaptable. To solve these challenges, real-world data access tools are essential, including:

  • Oracles that bridge smart contracts and off-chain data sources, enabling smart contract decentralized applications (dApps) to execute based on real-world conditions and infrastructure. To take full advantage of the blockchain’s decentralization, oracles integrated with smart contracts leverage multiple nodes for availability and trust, in order to solve the oracle problem and avoid any single point of failure, and write data such that it is readable by the contracts. The most common use cases for oracles integrated with smart contracts include price information for markets outside the smart contract platform and event information from other systems such as those used for supply chain verification or IoT sensor tracking.
  • Indexers, the inverse of an oracle, to enable efficient querying and categorization of on-chain data for use in smart contracts and dApps. Via indexers, users access contract and ledger data in a structured, indexed format. Indexer services typically ingest raw data from a ledger source, then warehouse the data, and enable users to construct and publish data entities for wider consumption.

Soroban's robust data access tools, including support for oracles and indexers, will provide developers with the necessary resources to connect smart contracts with real-world data and ensure accurate execution.

About

User interfaces

Beyond DeFi protocols that enable the code of a smart contract to run, and the data access tools that connect the smart contract to the real world, end users and developers need tools to interact with and interpret what is happening on-chain. An end user may want to know their account balance or whether or not their last transaction went through. They may also wish to know how liquid the market is or how many other people are participating in an AMM’s liquidity pool. Likewise, end users need a user-friendly way to manage and interact with their assets. Essential user interfacing tools include:

  • Block explorers that allow users to inspect accounts, transactions, or a series of transactions in a human-readable format. These systems unpack the chain’s blocks into an entity-based data structure, allowing them to convert on-chain identifiers included in individual blocks into object links which allow users to traverse the chain’s data. They also allow contracts to provide verified links to the code being run so that the raw operations can be converted back into the uncompiled code they are invoking. These services also offer the ability to look at historical activity for important objects on the chain like contracts or accounts, allowing a user to see how they interact over time.
  • Wallets that provide advanced features and a user-friendly experience for smart contract consumers. A fundamental building block for dApps and visible to the end user, digital wallets allow users to view balances and history and make payments. They may also be controlled by a smart contract, allowing users to leverage automation and customize behaviors of the account without needing to always provide their input.

About

Enabling Compatibility

Finally, in order for developers to trust using a smart contract as part of their application they need to be able to trust the underlying implementation. A thriving smart contracts ecosystem needs mechanisms in place to ensure this trust and security for its contracts. These essential mechanisms include:

  • Audit firms to review code, check for vulnerabilities or other issues, and suggest improvements to protocols.
  • Open-source contract templates that conform to common standards and are widely used throughout the ecosystem to reduce a contract’s surface area for audit in the first place.

About

Putting It All Together

To illustrate the interlocking nature of these ecosystem building blocks, we might imagine a DeFi end user without access to a traditional financial institution. This user is looking to lend digital assets to earn yield, without the fees, intermediaries, and inefficiencies associated with centralized lending markets. Once they download a smart wallet onto their phone, the wallet lets them deposit local currency cash through Moneygram and gives them USDC in return. Via the wallet, the user is then able to deposit a portion of their assets into an integrated lending market. As needed, the user can use a block explorer to check the status of their transactions. Without access to a traditional financial institution, this user could not deploy their capital to make a loan. Smart wallets and their DeFi capabilities make this possible for consumers globally, providing financial access and opportunities that would otherwise remain unavailable.

Behind the scenes, the app that enables the digital lending in this example leverages the many smart contract building blocks that power these DeFi capabilities. While the smart wallet interface is obviously central to the consumer experience, the app also leverages a DeFi lending protocol, which in turn uses an oracle to fetch prices in order to inform the consumer’s lending and exchange actions. Since these tools have already been built and integrated into the platform’s ecosystem, the app developer does not need to establish their own unique partnership with USDC to enable the user’s Moneygram deposit and exchange. They likewise do not need to create from scratch the functionality for the block explorer integration. Instead, all of these smart contract building blocks have already been wrapped in the platform’s standards and are ready for use by the ecosystem.

Soroban's comprehensive ecosystem and integration with the Stellar network will make it an ideal platform for building and deploying DeFi applications, providing users with financial access and opportunities that would otherwise remain unavailable.


Explore Next

Your Next Read

Oracles

Smart Contracts

Understanding blockchain Oracles in Smart Contracts.

View

Swap Functionality and AMMs

Smart Contracts

DeFi

Learn how Swap Functionality and Automated Market Maker work with smart contracts.

View

Stellar Developer Hub

Explore documentation, tooling, & community support to help you get your blockchain project up quickly. Take advantage of learning resources to…

View

Soroban: Smart Contracts Docs

Start building on Soroban today with the help of established tools and documentation

Go