Creating My Own Smart Contract

Aryan Khimani
4 min readNov 18, 2022

--

Blockchain technology has taken the world by storm with new cryptocurrencies and constant media mainstream attention has taken the idea of absolute security and trust into a force to be reckoned with. One thing you might have heard when people talk about blockchain are Smart Contracts. That might just sound like another concept with the word smart put in front of it. However, Smart Contracts are one of the key components that make blockchain technology tick. So you might be asking what they are, why they are useful and how can you make your own smart contract?

Ground Zero

So to start we need to define smart contract because without a proper meaning to use as a base, you will get lost reading this article.

Smart contract is a program with the terms, hence a contract. That agrees between buyer and seller directly written into lines of code. The code and the agreements contained in a distributed, decentralized blockchain network. You can think of it just like contracts in the real world, only it’s now completely digital. In fact, a smart contract is a tiny computer program stored inside a blockchain.

The term “smart contract” was first used by Nick Szabo in 1997, long before Bitcoin was created.

But if they are a contract that is completely digital, how can we make it so that it can’t be edited or destroyed by a benefiting third party?

Math Time

Well, the reason smart contracts can stay secure is through being stored on a blockchain. As in doing so, they inherit some interesting properties that make the contract immutable and distributed. Immutable means that once a smart contract is created, it can never be changed again.

Making it so no third party can tamper with the code of your contract. With it also being distributed makes it so no single person can force a contract on someone’s assets. Making tampering with smart contracts almost impossible. But what exactly are those properties that make it so that it’s immutable?

One of the methods they use to make the blocks tamper proof is using the hash feature

Well, let’s see what a smart contract may hold in it. Well, each contract contains some data, the hash of the block and the hash of the previous block. That data could be something like coins, assets, or even a message. Smart contracts also hold something called a hash. You can think of it as the contract’s ID. It identifies a block, and all of its contents, as the hash is one of its kind. Lastly, each block contains the hash of the previous block, making it practically impossible to tamper with the blockchain in turn for your transaction.

Private and Public Keys

Another piece of security that makes each transaction legitimate are private and public keys. You can think of these as digital signatures, just like how you would sign a contract, you would sign a smart contract. But this doesn’t mean you use your actual handwritten signature, but a mathematically secure key that is unique only to you.

Private and public keys both get generated for everyone who is a part of the blockchain. Each of those keys being unique to you, with the public key being like the name suggests, can be seen by everyone. The private key should be kept secret, as losing it can mean the loss of all your possessions. So how these two keys keep your contracts safe is just how a regular signature would be by making sure you are the one signing the contract and not an imposter.

The way it does it is through a mathematical function. When you sign a document in real, you use the same signature for every document. With blockchain, every time you sign a new contract your signature changes. With the function resembling Signature = (Message, Private Key) and to verify it was you who signed it, the function is Verify = (Message, Signature, Public Key)

Smart Contract Applications

Smart contracts can be applied to many different problems and systems, to name a few important ones, would be…

Crowdfunding, allowing for transactions of donations or assets to go to the people we intended the money towards. Banks could use it to issue loans or a more efficient history check making the bank overall run smoother with practically zero vulnerabilities. Insurance companies could use it to process certain claims and make sure these claims are legitimate. That just being the tip of the iceberg regarding applications of smart contracts

--

--

Aryan Khimani
Aryan Khimani

Written by Aryan Khimani

I’m 16-years old who is very passionate about using Gene Editing and Machine Learning to disrupt the world of biomedicine, using my knowledge of Python, AI, ML

No responses yet