Introduction

In Ethereum terms, smart contracts are immutable decentralized programs that run deterministically in the context of EVM. They are neither smart nor legal contracts, but the term has stuck.

Smart contracts are usually written in a high-level language like Solidity or Vyper and then compiled to bytecode.

Smart contracts are used to bring real world concepts and value to Ethereum.

Solidity is the main programming language used to write smart contracts for the Ethereum blockchain. It is a statically typed language that looks like C++, JavaScript, and Python.

It is a contract oriented programming language created by Gavin Wood. The main product is a compiler, solc, which converts programs to the EVM bytecode.

Solidity is a statically typed language, supports inheritance, and external libraries. It's a full blown programming language capable of writing sophisticated smart contracts.

Mainnet VS Testnet

Lifecycle of Smart Contract

  1. Smart contract is designed, implemented and compiled to bytecode.
  2. Smart contract is extensively tested and audited.
  3. Smart contract is deployed via a special transaction and its address is determined.
  4. Users automatically interact with a smart contract either directly or through DAPPs. The contract may in turn interact with other contracts.
    1. Dapps interact with smart contracts through function calls and event listening. They invoke functions defined in the contract using the ABI, which specifies function names, parameters, and return types. dApps can also retrieve contract data and respond to events emitted by the contract. This interaction enables dApps to execute functions, access contract state, and provide real-time updates based on contract events.
  5. Smart contract may be destructed if it allows so. (Deprecated feature)

Version pragma

All solidity source code should start with a "version pragma" — a declaration of the version of the Solidity compiler this code should use. This is to prevent issues with future compiler versions potentially introducing changes that would break your code.

pragma solidity ^0.5.2; will compile with a compiler version >=0.5.2 and <0.6.0.

Import files

When you have multiple files and you want to import one file into another, Solidity uses the import keyword.