Smart Contracts vs. Substrate Pallets: Important Building Blocks and Their Differences
Composable’s vision for Picasso is that it becomes an environment where the community is able to add various features and products directly into the runtime of the chain. That is, being able to be the chain in the Kusama and Polkadot ecosystems that allow for the integration of pallets into a parachain. However, here I provide a very high level explanation of pallets vs. smart contracts to educate readers about this decision.
Smart Contracts & Their Origins
Defined as self-executing and automatic agreements, smart contracts facilitate various processes along a blockchain protocol. These programs are able to interact with Ethereum and operate without any central authority or third party, adding to the trustless infrastructure of the decentralized ecosystem. This helps smart contracts to reduce costs and transaction speeds while also increasing transparency.
The true power of this technology is the output of a smart contract; a deterministic and built-in part of the blockchain’s consensus mechanism. Therefore, it is certain that its outcome is binding.
Despite some difficulties in interoperability with chains and layers they are not native to, smart contracts still provide an extremely valuable tool with a near-unlimited potential in what they can facilitate. This includes all of the transactions of digital assets in DeFi, whether it is a simple exchange or a complex yield aggregation deposit.
Substrate Pallets & the Progression of DeFi
In comparison to smart contracts, pallets are a new type of leverageable tool designed for building in DeFi. As the industry progresses towards an interoperable future, Polkadot is providing the necessary cross-chain infrastructure with pallets, as they are the way to build upon this technology.
Parity, the developer of Polkadot and Substrate, which is the blockchain framework that powers Polkadot, has described Substrate as “…a modular framework that enables you to create purpose-built blockchains by composing custom or pre-built components.” These custom, pre-built modules, are called pallets.
Pallets can be easily combined in Substrate and each pallet contains domain-specific logic, allowing for certain functionalities to be added to a Substrate-based chain, like Polkadot. Developers can also create their own in order to best meet the needs of their chain. Through pallets, developers can create chains with everything they need while omitting unnecessary pieces.
Smart contracts trigger trustless agreements, however, pallets provide a greater infrastructure framework that developers can build. Although, smart contracts can be used across more chains than pallets, which are limited to Substrate-based chains.
How Smart Contracts Fit Into Future of DeFi
As said before, smart contracts struggle with interoperability. However, they can still be incorporated into Polkadot, or Kusama, Polkadot’s canary network, through Parity’s ink! domain specific language (DSL). Ink! is essentially the Rust coding contract language plus a corresponding framework.
Utilizing Substrate’s modular design, smart contracts can be added to Polkadot through the contracts-pallet from Substrate. Though, without adding this or another smart contract’s pallet into a parachain/Substrate-based blockchain, such as the evm-pallet, which allows for smart contracts targeting the Ethereum Virtual Machine, smart contracts cannot run on Polkadot.
The Differences Between Building with Smart Contracts and Pallets on Polkadot
Beyond the aforementioned obvious and critical differences in functionality on Substrate, there are a number of differences between smart contracts and Substrate pallets that endow each with unique benefits and functions.
Beyond different builds, smart contracts add an additional layer of logic on top of a blockchain’s existing core logic. One benefit of this structure is that anyone can build onto and recreate an existing smart contract and its runtime logic to create a modified version of a given code or protocol. A particularly important feature to smart contracts is the way they perform cross-contract calling to delegate and message other contracts. Anyone is capable of publishing smart contracts onto existing blockchains, including malicious actors and inexperienced developers. However, there are a number of safeguards for this.
In contrast, pallets are compiled together to create the base runtime of a parachain. Runtime development has no safeguards against malicious actors and inexperienced developers. This is partially why Kusama and Polkadot are auctioning off their parachains to the most financially-backed crowdloans. These heavily-supported projects are likely those who are serious about their protocols and are strongly backed by community token stakers.
Pallets provide more control than smart contracts, allowing for a higher degree of customization and functionality. Such functionality includes blockchain hooks, the codes that are automatically triggered when blocks are generated. Some of these hooks include:
OnInitialize: executed right before the first transaction of a block is executed
OnIdle: Executed before the block is finalized, possibly adding more transactions depending on the leftover weight
OnFinalize: called after all transactions are applied
OffchainWorker: a worker function which is called at the end of a block. Workers can read chain state, but only mutate it through transactions. Workers may also use off chain storage, which does not bloat the chain, and perform non-deterministic actions such as HTTP requests
OnRuntimeUpgrade: called before OnInitialize when a runtime upgrade occurs
SignedExtensions are another added benefit to pallets, which can run arbitrary logic before and after each transaction. With the added control of pallets, custom events can be triggered to make a specific event happen. This can include; beneficial inflationary mechanics such as burning tokens on transaction fees or any other random events.
Within Polkadot’s ecosystem, it is easy to make pallets with governance tools. Not only can these tools provide robust governance capabilities, but they are also easy to integrate into a pallet’s infrastructure.
Pallets also provide granular control of transaction (TX) fees, allowing developers to be able to make certain, or all, TXs free. This implementation can get as specific as only charging fees when certain TX conditions are met.
All of this control provided by Substrate pallets creates a double-edged sword. More control in “bricking” or blocking your own chains means more room for errors, compared to smart contracts.
However, pallets and smart contracts still have a significant degree, in concept. Like smart contracts, Substrate pallets are able to coordinate with each other and different pallets can be callable by smart contracts via a contracts-pallet.
Smart contracts and Substrate pallets are both critical components in the construction of dApps. However, these tools function at different levels, with smart contracts adding an extra layer of a runtime to an existing chain’s runtime, and pallets acting to build the chain’s runtime itself. Pallets allow for a greater degree of customization, which comes with pros and cons. However, we believe that to accomplish our goals that we’d like to pursue within the ecosystem, offering our chain as a location where developers can deploy their pallets, and have them integrated after a governance vote, will be more efficient. We will likely have support for smart contracts, but given we initially want innovations built directly into the runtime of our chain, we are proceeding with this concept as a significant, community oriented aspect of Picasso.
If you are a developer with a project you think fits our ecosystem and goals, and you would like to participate in our interactive testing landscape at Composable Labs, reach out to me on Telegram at @brainjar.