What Are Smart Contracts And How Do They Work?

06.05.2021
guides

When Satoshi Nakamoto launched the Bitcoin blockchain, he also launched a new era of trustless online cash. Value could, for the first time, be sent from one user to another over the internet without relying on a third party like a bank or credit card company. 

Bitcoin includes a simple scripting language that allows for the creation of certain conditions around addresses and transfers. For example, multi-signature addresses can be created, so that (say) two out of three keyholders have to sign a transaction before funds are released. Or funds can be set to transfer only at a specific time in the future. But the scripting language is not ‘Turing complete’. It’s intentionally simple, rather than offering unlimited functionality.

Complex operations are required for blockchain-based use cases like games, decentralised exchanges, financial services, and much more besides. That’s where smart contracts, and platforms like Ethereum, come into play.

The origins of smart contracts

Smart contracts are code that runs on the blockchain. The idea of smart contracts was first raised by cryptographer Nick Szabo, back in 1996, before blockchain was even invented. The idea of unstoppable code that would run automatically when certain conditions were met would not become a reality for almost another 20 years, with the launch of Ethereum. As a global computing platform, Ethereum extended Bitcoin’s functionality from simple value transfer to the trustless execution of software. This could be anything from short scripts to far-reaching decentralised applications (dApps).

Ethereum’s dApps run exactly as programmed. Once started, they cannot be stopped by any third party, since their execution is enforced by the network of miners that secure the blockchain and process transactions. This also means that any loopholes or errors in dApps can be exploited, and there is no recourse for users who lose funds to a hacker. For this reason, developers who use Ethereum must be extremely careful to write accurate code, and dApps should be audited by experts before they are released.

There are other smart contract platforms that take a different approach, sometimes limiting the complexity of operations possible to reduce the security threat of mistakes in the code, but none have come close to Ethereum in terms of developer activity and user adoption

Paying the global computer

Bitcoin requires users to pay a small transaction fee for every transfer to another address. In Ethereum, the situation is more complex, and users are required to pay miners for every calculation they undertake. The more processing power an operation takes, the more expensive it is. Users pay for transactions in units called ‘gas’, with the gas itself costing a certain amount of ETH (the native token of the Ethereum blockchain) per unit.

For example, transferring ETH, the simplest transaction possible, costs 21,000 gas. At the time of writing, each unit of gas costs around 26 “gwei”, or 0.000000026 ETH, so sending any amount of ETH will cost 0.000546 ETH (21,000 * 0.000000026), though users can pay more if they want miners to process their transaction more quickly, or less if it’s not so urgent.

Transferring a token, like USDT or USDC, will cost around 42,000 gas, while swapping tokens on a decentralised exchange like Uniswap might cost upwards of 200,000 gas. That’s because such activities require interaction with smart contracts, which can become quite complex depending on the operations involved. In recent months, the increasing interest in Ethereum has meant users are competing for the limited space on the blockchain, pushing gas prices even higher.

The ongoing upgrade to Ethereum 2.0 is supposed to tackle the issue of high processing fees and make the Ethereum network & its smart contracts more viable.

Examples of smart contracts

The most common example of a smart contract on Ethereum is a token contract. Tokens are not ‘objects’ that are sent between users. In reality, they are more like records of ownership. When a user ‘sends’ tokens to another user, they actually instruct the smart contract to debit their balance and credit the recipient’s balance.

There are lots of other examples of smart contracts on Ethereum, including multi-signature wallets contracts, and automated market makers (AMMs) that exchange one token for another, setting the exchange rate according to supply and demand. But the possibilities offered by smart contracts go much further than this.

The DeFi movement

The decentralised finance (DeFi) movement is built on financial protocols – collections of interacting smart contracts that carry out a wide range of tasks and form a thriving alternative financial ecosystem. Major platforms include:

  • Decentralised freelance platforms like LaborX
  • The Maker Protocol, which enables users to generate the Dai stablecoin against crypto collateral
  • Lending protocols like Compound and Aave, which enables users to borrow one token against another locked as collateral
  • Decentralised exchanges and aggregators like Uniswap and 1inch
  • Asset management platforms like Yearn

Because these protocols are all built on Ethereum, and all use common standards, they are compatible with each other. That means their smart contracts can interact, and different protocols can be plugged together like Lego. This so-called ‘composability’ is a core feature of DeFi, and allows developers to build on top of existing protocols and users to access features and liquidity available from them.

The future of smart contracts

Ethereum’s smart contracts enable extremely powerful functionality and the creation of an alternative financial system that can exist without middlemen, allowing any user to take part, wherever they are in the world, with the only requirement being an internet connection.

The DeFi sector has grown from less than $1 billion in size at the beginning of 2020 to $20 billion at the start of 2021, and almost $70 billion four months after that. DeFi isn’t yet ready to take on the conventional financial sector, but – thanks to the functionality provided by smart contracts – it’s getting closer.



Flout
Marketing & PR
Comments : 0