What are Contracts?
Solidity’s code is encapsulated in contracts which means a contract in Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. A contract is a fundamental block of building an application on Ethereum.
POP vs OOP vs BOP
| Sr.No. | Title | Short | Language | Details |
|---|---|---|---|---|
| 1 | Procedure Oriented Programming | POP | C-Language | Functions and Procedure |
| 2 | Object Oriented Programming | OOP | CPP / Java / C# Languages | Classes State & Functions |
| 3 | Block Oriented Programming | BOP | Solidity Language | Contracts State & Functions |
Details
- Pragma:
Pragmas are instructions to the compiler on how to treat the code. All solidity source code should start with a “version pragma” which is a declaration of the version of the solidity compiler this code should use. This helps the code from being incompatible with the future versions of the compiler which may bring changes.
- Contract:
The contract keyword declares a contract under which the code is encapsulated.
- State variables:
State variables are permanently stored in contract storage that is they are written in Ethereum Blockchain.
- A function:
Functions are code blocks that perform specific tasks for different input parameters without repeating lines of code. The most common way to define a function in Solidity is by using the function keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.
Question / Answer
Pragma is generally the first line of code within any Solidity file. pragma is a directive that specifies the compiler version to be used for current Solidity file.
SPDX is an open standard for communicating software bill of material information, including provenance, license, security, and other related information. SPDX reduces redundant work by providing common formats for organizations and communities to share important data, thereby streamlining and improving compliance, security, and dependability. The SPDX specification is recognized as the international open standard for security, license compliance, and other software supply chain artifacts as ISO/IEC 5962:2021.