cover-img

Smart Contract and its Compilation Process

25 August, 2022

0

0

0

Contributors

Smart Contract!

Before starting the smart contract I hope all of you know about the simple contract. Right?

What is a Contract?

A contract is a written or spoken agreement, especially one concerning employment, sales, or tenancy, that is intended to be enforceable by law. In simple terms, it is a piece of paper where two parties make a contract that includes mutual assent and is enforceable by law.
Like this, we can make a contract with the help of a coding language(mostly solidity), which calls a smart contract. Or we can say a smart contract is a self-executing contract with the terms of the agreement between buyer and seller being directly written into lines of code. It is simply a program that runs on the Ethereum blockchain. It’s a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain.
Ohh, Ok Saroj. That’s a great feature. But wait, how to write them?

How to write a smart contract?

As you all know, to write a smart contract we need a coding language. And for that, we need an IDE where we can write our smart contract. As of now, Remix IDE is the favorite tool where we can write them. It is an open-source IDE. With the help of Remix, we can develop, deploy, and we can also administer our smart contracts.
Solidity is the most popular language to write smart contracts. In Remix, not only in Solidity but also with Vyper we can write smart contracts.
Interesting right? Yep, Saroj :) Can you please show a smart contract what it looks like?
Here I am writing a simple smart contract where I can store a number and I can retrieve that stored number.
As you can see above it is a simple smart contract. Let’s try to understand all of the lines. In the very first line, we have to mention the license number.
Then we have to mention a version number of solidity language. Also, we need to provide a contract name, in our case, it is Storage. Inside the storage contract, I am taking one unit256 type variable called number. And I make 2 functions named store and retrieve.
Cool. This is a simple smart contract program that takes one number and it will store that number with the help of the store function. And we can retrieve that stored number with the help of the retrieve function.
Well, this is fine Saroj. But how a smart contract compiles the code?

Compilation of a Smart Contract

img
When we compile a smart contract, it goes to the solidity compiler. Then the compiler checks all the lines for any errors. If the compilation process works fine, then it divides the smart contract into 2 parts.

1.

ABI

2.

Byte Code
1. ABI
ABI or Application Binary Interface is the Interface or we can say, it acts like a bridge between application and smart contract. If another smart contract or application wants to access our smart contract, then they must need the ABI. Let’s see what it looks like.
It is the ABI for the Storage smart contract. With the help of ABI, we can easily understand the structure of the smart contract.
2. Byte Code
Byte code is also generated from our smart contract at the time of compilation. It is helpful while the deployment of the smart contract in the blockchain network. Without Byte code we can not deploy a smart contract in the blockchain network.
Above is the Byte code for the same Storage smart contract. Byte code mainly consists of object and opcodes. The object is the binary form of the smart contract where opcodes act as an instruction to the smart object.
Ohh! now we are able to understand the smart contract, thanks Saroj!
This is a simple overview of the smart contract and its compilation process. I hope you found it informative and that you enjoyed it.
Thanks for the read. See you soon :)

0

0

0

Saroj

Bangalore, India

Software Engineer

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.