How Solidity and Smart contract Work - A Developers Overview

Kana Labs
3 min readMar 23, 2022

--

Developing smart contracts on blockchain requires a programmer to understand the underlaying technology blockchains exist on and the complications that it revolves around such as mining, hashing, elliptic-cure cryptography, and peer-to peer network. A developer should also understand what transactions and blocks are in a blockchain while building a smart contract.

Transaction-

In terms of solidity a contract exists on blockchain as a collection of code(functions) and data (state). They reside at a specific address on the blockchain. Their job is to modify data in a blockchain, in order to modify data in a blockchain, you have to create a transaction to participate in the blockchain network. A blockchain is globally shared and transactional database which means that everyone can read entries and participate in the network. The transactions are nothing but smart contract that reside on the blockchain which can be coded to make the change you want to the blockchain. These transactions should be accepted by all in the network which means that it should be either not done at all or completely applied. When a transaction is being applied no other transaction can alter it (assume you want to change two values at the same time). One of the concepts that a blockchain has is transactions are cryptographically signed. This makes it straightforward to guard access to specific modifications of the database.

Example- Imagine a database with list of all the balances in the account in an electronic currency. When a transaction takes place between two accounts, the transactional nature of the database ensures that the amount subtracted from one account is always added onto the other account. If the transaction is to fail it would mean that it was not possible to add the amount to the target and the transaction stays unmodified.

In a blockchain when a smart contract is applied there are ways to ensure that modifications are processed by predicting the transaction state.

Blocks –

There are cases when smart contract could fail when transactions are similar in nature. for example, when there are two transactions that want the same modifications, such as emptying their account. There is a possibility of double — spend attack since make (assume you want to change two values at the same time only one transaction can be valid, typically the one that is accepted first. First is not an objective term in a peer-to-peer network. It would be hard to know which transactions was valid on to the blockchain. This is because the transactions will be bundled up into what is called a block and the one that is rejected will not become the part of the block. Blocks form a liner sequence in time and are added to the chain in regular intervals.

In the same ways blocks are also rejected time to time a since the accumulate over time meaning that the transactions are reverted or even removed from the blockchain. This is due to the blockchain order selection mechanism called mining. In order to solve this issue blockchain companies like Ethereum have developed Ethereum Virtual machines EVMs to prevent blocks accumulating overtime when a smart contract is executed.

--

--

Kana Labs
Kana Labs

Written by Kana Labs

Web3 & Blockchain Tech specialist developing Cross Chain and Account Abstraction Smart Wallet solutions.

No responses yet