Skip to content

Smart Contracts: What Are They?

smart contracts: what are they - header image

Smart Contracts: What Are They?

Smart contracts are automatically executed contracts written on the blockchain technology that eliminate the need for any third party to complete an arrangement between two parties.

In simple words, smart contracts are lines of code programmed on the blockchain, most often using the Solidity programming language.

They work on an algorithm basis, which in simplified form can be compared to the IF function in Excel, meaning that if X (a certain condition) is met then Y (a certain outcome) is triggered to happen.

The conditions we’ve just talked about are also verified by the blockchain’s validators who share their computing power to confirm the events that need to happen for a smart contract to be triggered.

If the events are validated and the GAS fee is paid, the smart contract is automatically executed and the coded outcome is set to happen.

A Simplified Example

Mark wants to sell his NFT, so he decides to auction it on OpenSea (one of the more popular decentralized platforms for selling and buying NFTs) and Kate decides to purchase it from Mark through the decentralized platform.

Now, when using decentralized platforms for transactions like this one, a smart contract is working in the background to make sure everything runs smoothly. 

Therefore, the smart contract checks if Kate transferred the right amount of crypto to Mark and checks if the NFT got transferred to Kate. The whole operation gets completed only if every condition of the agreement has been met and validated.

But there’s a few more details.

Also happening in the background, blockchain’s validators confirm those events in order for the smart contract to trigger the coded outcomes. Kate also has to cover the GAS fee before the operation gets completed.

Smart contract is then automatically executed, Kate gets her NFT, Mark gets his crypto, everyone lives happily ever, and the whole interaction is recorded on the blockchain.

Want to Know More?

If you’re still curious to know more about smart contracts and dive deep, there’s a whole lot to uncover on this topic and we do exactly that in this article. You’re free to join in!

We’ll do our best to explain what smart contracts actually are, how they work, if they are as trustworthy as they are painted to be, if there’s any room for errors, how to use smart contracts, and more.

We also divide our article into regular, simple use of smart contracts that doesn’t require any coding, e.g., when making a transaction on a decentralized exchange platform and the more complex use of smart contracts that does require coding.

Let’s get started!

An In-Depth Explanation of Smart Contracts

A Wikipedia definition of a smart contract says that it’s a computer program or a transaction protocol that is set to execute, document, and control contracts and their terms in an automatic way.

So in a nutshell, it’s a blockchain-based programming code that works on an algorithm basis. The smart contract is programmed to trigger a certain event provided another set event has occurred and has been validated by the blockchain miners.

Which Programming Language Is Used for Smart Contracts?

The programming language that is brought up to be the most often used for coding smart contracts is the Solidity programming language.

Solidity was invented exactly for writing and implementing smart contracts, focusing primarily on the Ethereum blockchain.

Fees and Validators

As was already briefly mentioned, smart contracts rely not only on algorithms to check and validate different events or conditions. It’s the blockchain’s validators who have to confirm the events on the blockchain and therefore, whether the smart contract’s terms are being met.

They basically share their computing power to validate different events on the decentralized network.

Now, directly connected with the validators is the GAS fee, which basically is a transaction fee paid to the network’s validators as an incentive or reward for their services.

So each time a smart contract is started, a GAS fee must be paid. In the event of a GAS fee not being entirely covered, again the smart contract will not trigger its predetermined events.

Now, the actual price of the GAS fee is highly volatile and depends on many different factors. For example, a high number of blockchain users, meaning more people competing for priority of transaction, results in a higher GAS fee.

Because the higher you set your GAS fee to be, the quicker your transaction will be finalized.

What’s interesting is that the GAS fee is measured in gwei, i.e., a very small denomination of Ether.

If you’re still curious about GAS fees and want to know the formula to calculate one, here’s an in-depth article worth reading on this topic, explaining the whole thing pretty well.

Where Are Smart Contracts Stored?

Since smart contracts are written and validated on the blockchain technology, they are also stored on the blockchain.

Which means that they are stored on a decentralized, distributed database. So basically within the blocks of the blockchain, which we talk more about here.

Do Smart Contracts Source Data Outside of Blockchain?

Smart contracts are not limited to source their data only from within the blockchain. And the thing that helps smart contracts source data from outside of the blockchain is called an oracle.

In simplified words, oracles are data feeds that help smart contracts receive information from the outside (off-chain) world to eliminate the limitation of having to work only based on the data available on the blockchain. 

Oracles use oracle nodes to extract data from different external sources, for example APIs from third-party servers and transfer it from off-chain to on-chain for smart contracts to acknowledge.

Official Ethereum’s docs give an example of a decentralized application that offers bets and monetary rewards for correct ones. The example they gave was someone betting on who’s going to win the next presidential election and betting 20 ETH. In that case, the smart contract needs outside information on the elections winner and oracles are what’s going to help extract that information from off-chain (real world data) and place it on-chain for the smart contract to trigger next events, in that case transferring the reward to the betting person.

Oracles can also transfer information from the blockchain to the off-chain sources if needed.

How to Use Smart Contracts?

Now for the real fun part: using a smart contract.

Do you need to be a developer or know any programming language to use an already available smart contract?

The answer is no.

Many cryptocurrency users have already used smart contracts, even if unknowingly. Because whenever you use a decentralized exchange platform that’s based on the blockchain technology, each and every operation happens automatically with a smart contract watching over it.

Regular Smart Contract Usage

Using a Decentralized vs Centralized Exchange Platform

Now, as was already said, each time you’re using a decentralized exchange platform, a smart contract is watching over and automating your operations.

As opposed to using a centralized exchange platform, such as Binance. The main difference here is that on centralized platforms, the fee we’re paying goes to the company that established said exchange platform and they in turn take care of completing and validating operations.

When it comes to decentralized exchanges, the fee goes to all the network’s miners that provide their devices and computing power to validate different operations and help support the whole network. As we already explained, the fee in this case is called the GAS fee and differs based mainly on the number of network’s users competing for priority of transaction.

So in short, on centralized platforms you’ve got a company standing behind operations and on decentralized platforms you’ve got a whole lot of network’s miners who validate operations and smart contracts automatically triggering validated events. 

Now what does using a smart contract on a decentralized platform actually look like?

Well, good thing you ask, because we did prep a step-by-step guide with an example transaction using a smart contract to showcase just how simple it actually is.

Step-By-Step Decentralized Transaction Example

For the purpose of showcasing how simple using an already available smart contract actually is, we’ll use Uniswap.

Uniswap is one of the most popular decentralized exchange platforms that works on Ethereum’s blockchain.

Now, let’s say we want to make a simple currency swap on Uniswap.

What do we have to do?

After reaching Uniswap, we choose Swap from the top menu and follow the guidelines and steps the app takes us through.

So, first, we have to connect our wallet. In our example that was the MetaMask wallet, which is one of the most popular wallet extensions to use for such operations.

Once the wallet’s connected, we choose the tokens we want to swap, hit the Swap button, check the fees, click on Confirm Swap, and then look at the final GAS fee calculated for this operation to take place.

If we’re confident that our wallet can cover the calculated GAS fee, we hit the final Confirm button and the swapping process begins without any further involvement from our side.

Everything we’ve just gone through here is visible on the step-by-step illustrations below.

Disclaimer: we’ve used Uniswap and Metamask for the purposes of showcasing triggering a smart contract to start and the ease of their use when completing operations on a decentralized exchange platform. But both the platform and the wallet are just sample and the same operation using different tools, may obviously look differently.

Step One: Swap

smart contracts: what are they: example transaction

Step Two: Connecting a Wallet

smart contracts example

Step Three: Wallet Connected

example for the smart contract article

Step Four: Select a Token

smart contracts: what are they: example transaction

Step Five: Swap

smart contracts: swap operation example

Step Six: Confirm Swap

smart contracts

Step Seven: Gas Fee Details and Final Confirmation

gas fee details example

As you can see the use of a smart contract for a regular user is nothing to be scared of. Whenever you’re choosing to use a decentralized exchange platform, each operation will happen with a smart contract working in the background.

So for the regular user or trader, the use of smart contracts is something that comes off pretty effortlessly. There’s no coding involved, no programming, no advanced or difficult knowledge. We just have to go through the transaction as if we were buying something online, with a few steps and a few mouse clicks, all happening on a pleasant-to-the-eye interface.

Developers on the other hand can write smart contracts for more complicated uses, which is pretty advanced and does require coding on the blockchain. But that’s not something that should bother regular traders.

Advanced Smart Contracts Usage

Theoretical Example of Personal Smart Contract Usage

Let’s say you have the coding skills to write a smart contract for personal usage.

We’ll give you a theoretical example on a case in which you could use a smart contract, just to illustrate how this technology could actually be used.

Let’s imagine you want to bequeath your cryptocurrency savings to your spouse and you don’t necessarily want to use a notary for it.

You could potentially do it with a smart contract instead.

In that case, you could write a smart contract that’s triggered after your wallet’s address has not seen any operations that you’ve started. Your crypto savings would automatically be transferred to your wife’s wallet address once that condition is met.

So if you’ve got the IF condition and the outcome that should be triggered by the smart contract coded within a blockchain, then the operation or the “agreement” should be performed automatically.

Of course, this is all theoretical for now and such cases are pretty extreme, because writing a smart contract is complicated to say the least.

Room for Errors and the Question of Safety: How to Avoid Scams?

In one of our articles, we’ve said that the best way to avoid scams or unsafe situations with smart contracts, is to go for ones that are already available on the market and that are known to work well.

Let’s elaborate a bit on this part now.

That statement is often true when engaging with DeFi, i.e., decentralized finance. If you haven’t read our article about DeFi, decentralized finance is basically a mirror reflection of centralized finance (our traditional financial system), but built on the blockchain technology and eliminating the third parties in operations.

So in DeFi, you can perform the same operations as with a traditional finance system, but without the third party and their fees needed.

Meaning that there’s a DeFi version of lending, borrowing, transferring money, and more.

Now why are we mentioning this?

Because DeFi uses smart contracts to perform all of these operations.

If you were to engage in DeFi lending, you would be using smart contracts in a bit more advanced way than just using a decentralized exchange platform that guides you through all the steps and does all the nasty work for you.

In such a case, you would have to ensure that the smart contract you’re choosing to use has been written in such a way to be uneditable and to be publicly available to check.

One thing we always have to keep in mind is that smart contracts are coded by people. Meaning that there is room for errors and that’s why it’s best to go for smart contracts that have already been on the market for a while and are known to work well.

Smart Contracts and Decentralized Applications (dAPPs)

When it comes to other advanced usage of smart contracts, we have to briefly mention dAPPs because smart contracts play a big role in building them.

DAPPs are decentralized applications coded on the blockchain technology, meaning that they eliminate the need for the one, central party governing all the user’s data. Instead, the data is distributed on the blockchain and the whole network is supported by its miners, their computing power, and by them validating operations.

This could lead to building mirror reflections of applications and systems we know now, but in a decentralized way to ensure more data security and no censorship.

For example, we could have a decentralized version of eBay that doesn’t necessarily limit its users as to what they can put on sale.

On the other hand, lack of censorship may lead to underage users reaching adult content more easily.

But decentralized applications alone is a pretty big topic, so we’ll get all into that in a separate article to keep things more simple.  

Our Thoughts on Smart Contracts

As per usual, the conclusion is that smart contracts are pretty revolutionary and will definitely shape our future in some kind of way. But there’s still a long way ahead of us to be able to reach the full potential of smart contracts and decentralized applications alike.

Not every industry may take advantage of smart contracts just yet, while in others it may optimize and speed up some of the processes, reduce the operational costs, and get rid of any issues.

Right now, they play a big part in any operations performed on the decentralized exchange platforms, such as our article example Uniswap. The smart contract works in the background to make sure everything runs smoothly, network’s validators help out with validating the events that need confirmation, and the regular user gets a pleasant and easy to use interface to perform their operations.

Advanced uses include building decentralized applications – dAPPs, DeFi lending, borrowing, and other operations, and more unique uses, such as e-voting, keeping clinical records, or handling NFTs.