Solidity Documentation - Read the Docs

Solidity Documentation

Release 0.8.24 Ethereum

Nov 10, 2023

BASICS

1 Getting Started

3

2 Translations

5

3 Contents

7

3.1 Introduction to Smart Contracts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.2 Solidity by Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3.3 Installing the Solidity Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

3.4 Layout of a Solidity Source File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

3.5 Structure of a Contract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

3.6 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

3.7 Units and Globally Available Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

3.8 Expressions and Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

3.9 Contracts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

3.10 Inline Assembly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

3.11 Cheatsheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158

3.12 Language Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

3.13 Using the Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

3.14 Analysing the Compiler Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

3.15 Solidity IR-based Codegen Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204

3.16 Layout of State Variables in Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

3.17 Layout in Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216

3.18 Layout of Call Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

3.19 Cleaning Up Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

3.20 Source Mappings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

3.21 The Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

3.22 Contract Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240

3.23 Contract ABI Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

3.24 Security Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260

3.25 List of Known Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

3.26 Solidity v0.5.0 Breaking Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288

3.27 Solidity v0.6.0 Breaking Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296

3.28 Solidity v0.7.0 Breaking Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299

3.29 Solidity v0.8.0 Breaking Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301

3.30 NatSpec Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304

3.31 SMTChecker and Formal Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308

3.32 Yul . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326

3.33 Import Path Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348

3.34 Style Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357

3.35 Common Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379

i

3.36 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385 3.37 Contributing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388 3.38 Language Influences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 3.39 Solidity Brand Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397

Index

401

ii

Solidity Documentation, Release 0.8.24

Solidity is an object-oriented, high-level language for implementing smart contracts. Smart contracts are programs that govern the behavior of accounts within the Ethereum state. Solidity is a curly-bracket language designed to target the Ethereum Virtual Machine (EVM). It is influenced by C++, Python, and JavaScript. You can find more details about which languages Solidity has been inspired by in the language influences section. Solidity is statically typed, supports inheritance, libraries, and complex user-defined types, among other features. With Solidity, you can create contracts for uses such as voting, crowdfunding, blind auctions, and multi-signature wallets. When deploying contracts, you should use the latest released version of Solidity. Apart from exceptional cases, only the latest version receives security fixes. Furthermore, breaking changes, as well as new features, are introduced regularly. We currently use a 0.y.z version number to indicate this fast pace of change.

Warning: Solidity recently released the 0.8.x version that introduced a lot of breaking changes. Make sure you read the full list.

Ideas for improving Solidity or this documentation are always welcome, read our contributors guide for more details.

Hint: You can download this documentation as PDF, HTML or Epub by clicking on the versions flyout menu in the bottom-left corner and selecting the preferred download format.

BASICS

1

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download