阅读
编辑
历史
通知
分享
Solidity
Solidity is a curly-bracket, high-level, and object-oriented programming language created for designing and implementing smart contracts.[3][7]
Overview
Solidity is a curly-bracket language that has been influenced and inspired by several well-known programming languages. Solidity is most profoundly influenced by C++, but also borrowed concepts from languages like Python, JavaScript, and others.[7]
Solidity is a contract-oriented programming language designed by the Ethereum Network team for implementing smart contracts. It draws inspiration from programming languages like C++, Python, and JavaScript, and interacts with the Ethereum Virtual Machine.[1][2]
The basic concepts of Solidity revolve around enabling developers to create decentralized applications (DApps) and self-executing contracts on blockchain networks.
Historical Development of Solidity
In August 2014, Gavin Wood, co-founder of Ethereum, proposed the idea for Solidity. Later, the Solidity team of the Ethereum project, under Christian Reitwiessner, created and developed the language.[8][9]
Solidity was first released on August 7, 2015, with version 0.1.0. Initially, the language had basic and limited features, but over time, Solidity has undergone numerous improvements and developments.
Solidity quickly gained popularity among Ethereum developers, becoming the primary language for developing smart contracts. With Solidity, developers could write code that would be executed on the Ethereum blockchain to perform various functions and services.
Solidity has been used in various blockchain projects and decentralized applications (dApps). Smart contracts written in Solidity can serve multiple purposes, including ERC-20 tokens, voting systems, time-locked funds, and more.[10]
Influences by other languages
The influence from C++ can be seen in the syntax for variable declarations, for loops, the concept of overloading functions, implicit and explicit type conversions and many other details.[7]
Solidity used to be partly influenced by JavaScript. This was due to function-level scoping of variables and the use of the keyword 'var'. The JavaScript influence was reduced starting from version 0.4.0. Now, the main remaining similarity to JavaScript is that functions are defined using the keyword 'function'. [7]
Solidity also supports import syntax and semantics that are similar to those available in JavaScript. Besides those points, Solidity looks like most other curly-bracket languages and has no major JavaScript influence anymore. [7]
Another influence to Solidity was Python. Solidity’s modifiers were added trying to model Python’s decorators with a much more restricted functionality. [7]
Solidity Compiler v0.8.27 was released on September 4, 2024.[5]
Main Characteristics
-
Statically-typed: Solidity prevents mistakes, such as syntax and type errors, by verifying that every variable in the source code has a data type before it is executed to ensure that the application operates smoothly.
-
Contract-oriented: The programming language is designed to create smart contracts, which are self-executing contracts containing terms of agreement written into lines of code. These contracts can be used to create decentralized applications (DApps) and execute transactions on the Ethereum network.
-
Object-oriented: Solidity uses objects (data structure or self-contained units of code) to present data and their behavior to allow developers to organize code in a structured and modular way.[1]
Fundamental Concepts
Following are some fundamental concepts of Solidity.[3][4]
-
Smart Contracts
Smart contracts are self-executing agreements with the terms of the contract written in code. Solidity is used to create these contracts, defining their rules, conditions, and actions. -
Data Types
Solidity supports various data types, including integers, booleans, addresses, and more, similar to other programming languages. Developers use these types to declare and manipulate data in smart contracts. -
Functions
Smart contracts consist of functions that define the contract’s behavior. These functions can be called internally or externally, enabling interaction with the contract. -
Variables
Solidity allows the declaration of state variables to store data permanently on the blockchain. These variables maintain their values across function calls. -
Events
Events are a way for contracts to communicate with external applications, allowing them to subscribe to and react to specific occurrences within the contract. -
Inheritance
Solidity supports contract inheritance, enabling the creation of modular and reusable code. -
Ethereum-specific Concepts
Solidity integrates Ethereum-specific concepts like gas (transaction fees), ether (cryptocurrency), and the Ethereum Virtual Machine (EVM), which is responsible for executing smart contracts. -
Security
Security is a critical consideration in Solidity. Developers must understand vulnerabilities like reentrancy, integer overflow, and more to write secure contracts.
Solidity is available on smart contracts including:[6]
Ethereum and Solidity
The combination of Ethereum and Solidity made it possible for developers to create a wide range of complex applications. With Ethereum providing a decentralized platform and Solidity providing a robust programming language, developers have the tools they need to create secure, efficient, and transparent smart contracts.
Developers write smart contracts in Solidity and then deploy them on the Ethereum blockchain. Once a smart contract is deployed, it exists independently from any other contracts or applications. It has its own Ethereum address and balance, and it can make and receive transactions just like any other participant on the Ethereum network.
When a smart contract is triggered by a transaction, the Ethereum network executes the contract's code. This code can perform a wide range of actions, from transferring funds to interacting with other contracts.[11]
Advantages
-
Enables flexibility by allowing developers to create custom data structures, functions, and complex smart contracts.
-
Provides an interface, known as Application Binary Interface (ABI), that allows type safety to signal that there’s an error whenever there’s a mismatch in the data type of a variable. ABI is a set of rules and specifications that define how a smart contract can interact with other smart contracts.
-
Translates user-oriented requirements and specifications into a language that can be understood by machines.
Drawbacks & Challenges
- Security: The language is vulnerable to reentrancy attacks, which occur when a contract allows a malicious user to repeatedly call a function in such a way that the contract’s state is exploited.
- Irreversibility: Blockchain’s immutable nature ensures that a smart contract, once deployed, cannot be modified or removed. Because of this, it’s crucial to make sure that every single line of code is flawless to prevent the risk of exploitation or hacking.
- Precision: Solidity has arithmetic precision issues, where the language does not support fixed or floating-point values.
Another challenge was to cope with the scalability and efficiency issues of Ethereum, which limited the throughput and speed of smart contracts, and increased the costs of gas, the fee required to execute transactions on the network.[9]
And also, keeping up with the innovation and competition in the blockchain space was another challenge as new platforms and languages emerged, offering different features and trade-offs for smart contract development.
To address these challenges and meet the needs and expectations of the community, Solidity is constantly evolving and improving over the years, through regular updates and enhancements.
Some of the most significant changes include the introduction of new types, such as structs, enums, and mappings, the support for inheritance, interfaces, and libraries, the addition of modifiers, events, and error handling, the implementation of security checks and best practices, such as the require and revert functions, the optimization of gas usage and bytecode generation, and the integration with external sources and systems, such as oracles and inter-blockchain communication.[9]
Solidity
参考文献
[1]
[2]
Dappuniversity - Solidity for Beginners · Smart Contract Development Crash Course
Sep 14, 2024
[3]
[4]
[5]
[6]
[7]
[8]
[9]
LinkedIn - How did Solidity emerge as the dominant language for smart contracts on Ethereum?
Oct 6, 2024
[10]
[11]