DEV Community

Cover image for Smart Contracts

Posted on


Smart Contracts

What is a Smart Contract?

I’m writing to discuss smart contracts and their relationship with blockchain. This blog assumes that you have a general understanding of what a blockchain is and how it operates. If not, I ‘ve attached a link that provides a brief rundown. In addition, by the end of this read I’m going to help you learn how to write and deploy a contract using the oracle provider, Chainlink.

A basic definition of a smart contract is a computer program that exists on a blockchain and self-executes an agreement. However, if you go to, you will find a more robust definition that outlines some of the key steps needed to build a smart contract.

An important one is that a smart contract is an actual Ethereum account. It has its own address where it resides on the blockchain and, in turn, has an ability to make financial transactions. So, not only will we write a smart contract but we’re going to deploy it to the Ethereum blockchain.

Smart contracts are immutable agreements or programs. Once it’s deployed and the code is executed it cannot be reversed. Some interesting use cases for smart contracts are lotteries, elections, or real estate transactions. In the last case, think of the blockchain as a notary public that bears witness and holds record of the smart contract.

One of the important features of a smart contract is that it takes real world data and attaches or binds it to the blockchain. In the use cases mentioned earlier, I provided examples of events or occurrences that can be added to the blockchain. But, this begs the question. If the data on a blockchain is immutable, and a smart contract, irreversible, how can we verify the data in a smart contract is legit?

Enter the Oracle. All hail the oracle. What the heck is an oracle?

An oracle is a way to send real world, verified data to execute a smart contract and potentially disperse money. It’s important to understand the concept of proof of work in blockchain mining to fully understand how oracles work. When someone makes a transaction on a blockchain, miners verify that the transaction is authentic before it is broadcast and entered into the ledger. It is the solution to the Byzantine General’s Problem and the ethos behind decentralization.

With oracles, it is the same procedure minus the hashing algorithm. Once a certain amount of people(nodes) verify that the data is correct, it can be passed along to the smart contract and blockchain.

In order to learn how to write a smart contract, I went to the Chanlink developers documention and followed a simple walkthrough for writing and deploying my first contract. Below is an example of a smart contract’s architecture. It’s slightly different than a typical class but follows the same convention. At the top, the Solidity language version must be declared. It’s followed by the contract keyword which is the equivalent of class in Javascript. It has a constructor which holds some state and a function written to execute some code.

pragma solidity 0.8.7;

contract sayHelloWorld {
    string public message;

    constructor(string memory initialMessage) {
        message = initialMessage;

    function updateMessage(string memory newMessage) public {
        message = newMessage;
Enter fullscreen mode Exit fullscreen mode

If you follow the link above, you can learn how to do this in about fifteen minutes. First, you need to download the Metamask, software wallet. Then, you’ll need to fund it with some fake Ethereum or Chainlink. After that, you go to the Remix IDE where a premade contract to get price data for Ethereum is set to go. If you’ve built web applications before you’ll be familiar with compiling and deploying your code. However, it’s much easier with a smart contract because the code is minimal and doesn’t hold much complex data. Give it a try.

Top comments (0)

50 CLI Tools You Can't Live Without

>> Check out this classic DEV post <<