In the context of blockchain technology, smart contracts are self-executing software programs that trigger when certain conditions, specified in their code, are met. Smart contracts improve security and trustlessness across distributed networks, automate operations in blockchain systems and make DLT protocols programmable. They are the main mechanism that enables decentralized applications to run on networks like Ethereum.
In this article, we’ll have a quick refresher on how smart contracts work and why they’ve played – and continue to play! – such a crucial role in the evolution of blockchain technology. Most importantly, we’ll examine some of the most prominent developments and trends in smart contract development. So
How do smart contracts work?
Blockchains like Ethereum that support smart contracts have two main types of accounts – user accounts and smart contract accounts. User accounts have public addresses (usually referred to as public keys) to which transactions can be sent and are controlled by the holders of their associated private keys. A public key – private key pair is known as a wallet. In comparison, contract accounts do not have private keys because they are controlled only by the code written in them. However, they do have public addresses, meaning that they can receive transactions just like user accounts. This is how smart contracts are triggered.
Triggering a smart contract is done by meeting certain conditions to make the contract execute certain operations. Both the conditions and the operations are specified in the contract’s code. Meeting a smart contract condition may require sending a set amount of tokens or a message to the contract’s account. On Ethereum, both of these actions are done via transactions. Deploying a smart contract in the first place requires sending a transaction containing the contract’s code.
Once a smart contract has been deployed to the network, it can perform a variety of actions, based on its code. One simple application of a smart contract can be to distribute tokens among a set number of user accounts. However, smart contracts can also be used to trigger other contracts or even set up new contract accounts. By utilizing their capabilities in creative ways, developers are able to use smart contracts to create a variety of innovative applications.
One thing to consider is that once deployed to the mainnet, smart contracts become immutable, meaning that even their authors cannot make changes to their code. Because of this, smart contracts undergo rigorous testing so that any potential errors and inefficiencies in the code can be identified and fixed before the final deployment.
What can we do with smart contracts?
As mentioned above, smart contracts have a variety of applications and developers keep coming up with new ways to utilize them to power a wave of decentralized applications. The growing popularity of DeFi (decentralized finance) apps and this year’s NFT boom are perfect illustrations of smart contracts’ capacity to increase the utility of blockchain platforms and expand the reach of distributed ledger technologies.
On these pages, we’ve already talked extensively about how smart contracts and blockchain technology can be used to power a new generation of effective and efficient enterprise-grade solutions for a variety of industries – from supply chain management through healthcare and pharma to automotive. But even more interesting are the types of blockchain-centric applications that are only possible on DLT.
One of the main products of blockchain technology, asset tokenization, is only possible because of smart contracts.
Ethereum, which has been the main driving force behind asset tokenization, has two main standards for writing token contracts: ERC-20 for fungible tokens like utility tokens, security tokens, and cryptocurrencies; and ERC-721 for non-fungible tokens (details below).
When talking about asset tokenization, we need to mention Hedera Hashgraph, a DAG-based DLT protocol that has a novel approach to creating digital assets. Developed by LimeChain as part of our ongoing collaboration with Hedera, the Hedera Token Service (HTS) enables applications to mint, configure and manage tokens on Hedera, without having to write and deploy smart contracts. Tokens created with the HTS can represent anything from stablecoins to in-game reward coins.
Non-fungible tokens, or NFTs, are a special type of tokens that preserve unique digital assets such as digital collectibles, art, and so on. Here, smart contracts are typically used to mint the NFTs. An NFT smart contract usually contains much more detailed information than a fungible token contract. This includes metadata that describes what makes the token unique, information about the owner, file links, and so on.
Decentralized Autonomous Organizations utilize smart contracts to power governance mechanisms that allow them to operate without centralized leadership. Essentially, DAOs are blockchain-based organizations that are governed by their members. The governing rules of a DAO are written in a smart contract.
Decentralized finance has gained significant traction over the past couple of years, as blockchain developers have been finding more and more ways to create innovative financial services with the help of smart contracts. The rise of DeFi has given us things like liquidity mining pools, flash loans, crypto asset swaps, auto market makers, and more.
Cross-chain token transfers
Smart contracts can also be used for transferring tokens from their native blockchain to another via a blockchain bridge. Now, it’s important to clarify that actual token transfers between separate blockchains are impossible. However, by using smart contracts (other methods are also possible), developers can utilize locking and minting of tokens to achieve the same effect.
The first operation locks the amount of tokens a user wants to transfer to a target chain, temporarily removing them from the token supply of the native chain. Then an equivalent amount of ‘wrapped’ tokens is minted and becomes available for use on the target chain.
When the user decides to redeem their assets, the wrapped tokens are burned on the receiving chain, while the original tokens are unlocked on their native chain.
What are the smart contract development trends?
As we saw above, even in its early form, the technology has been able to power an impressive range of applications. But as with all things blockchain, smart contracts undergo continuous evolution and refinement in order to become even more powerful tools for developers. And smart contract development is poised to become even more intensive in the coming years. Here are some of the current trends that are expected to further grow and develop.
Upgradable smart contracts
The fact that smart contracts become immutable once they are deployed on a mainnet is overall a good thing, but it creates complications and inconveniences during smart contract development. For example, it limits developers ability to make upgrades and fixes to live contracts. This is why many blockchain projects have been exploring ways to enable upgradable contracts. One way to achieve that on Ethereum is by using third-party solutions like OpenZappelin.
Using Open Zeppelin’s Upgrades plug-in, developers can make modifications to a smart contract code, while preserving the contract’s address and state. The process of creating an upgradable contract with OpenZeppelin involves the deployment of three separate smart contracts: an implementation contract, which contains the executable computer code; a proxy to the implementation contract that holds the state and delegates calls to the implementation contract; and a proxy admin.
In this setup, a user always interacts with the proxy, which never changes its address, while the actual code is provided by the implementation contract. So to upgrade a contract, a developer needs to deploy a new implementation contract containing all the necessary fixes and changes to the original and update, via a transaction, the proxy’s implementation address to the new one.
Upgradability in Flow
While the OpenZeppelin method and similar solutions by other third-party providers make it possible to have upgradable contracts on Ethereum, they have some limitations stemming from the lack of native support for the feature on Ethereum and in its programming language Solidity. This is something that Flow, a promising protocol with a focus on digital collectibles and blockchain-driven games, aims to avoid.
One of the distinct characteristics of Flow is that it has a built-in support for upgradable contracts. The way it works is that the protocol allows smart contracts to be deployed on the network in beta mode, which leaves them open to modifications. However, users interacting with such contracts are automatically alerted about the unfinished nature of their code. Once the developers are certain that their contracts work as intended, they can release their control over the contracts, making them immutable. Also worth noting is that Flow comes with logging support, which allows developers to track the behavior of smart contracts.
The Diamond standard
While on the subject of upgradability, we also need to mention the Diamond standard. It’s a smart contract standard that allows a contract to use the external functions of other contracts as its own. Because of their ability to use external smart contracts, or ‘facets’, diamond contracts are very flexible and easily upgradable.
While Ethereum is by far the most popular smart contract platform, there are no shortage of blockchain projects looking to challenge its dominance. These include long-established projects such as Cardano and EOS, as well as a wave of fresh challengers like Binance Smart Chain, Polkadot, Avalanche and Solana. But while they seek to beat Ethereum for the smart contract crown, some of the challengers, like BSC and Avalanche, for example, also support compatibility with the Ethereum Virtual Machine and, as a result, offer some level of cross-chain interoperability for Ethereum-based smart contracts.
What are dedicated smart contract chains?
Another interesting development is the emergence of chains/protocols dedicated exclusively to handling smart contracts. An example of this is BSC, which is designed for supporting smart contracts, while Binance’s other chain, the Binance chain, has high transaction capacity as it is aimed at decentralized exchanges. The two chains run in parallel with each other.
Avalanche employs a somewhat similar approach as it has three different chains that run on two different consensus algorithms – Avalanche, which supports fast transactions, and Snowman, which offers secure smart contracts.
All of the above demonstrates clearly that smart contracts are not only one of the most important components of blockchain and DLT, but they are also poised to continue to play an important role in the evolution of space. Historically, many of blockchain’s most promising applications have come as a result of the clever use of smart contracts and as the technology continues to develop it is likely to produce even more interesting results.