Solidity
Solidity é uma linguagem de alto nível, orientada a objetos, para implementar smart contracts na blockchain Ethereum e outras plataformas compatíveis.
Solidity foi projetada para a Ethereum Virtual Machine (EVM). É tipada estaticamente, suporta herança, bibliotecas e tipos complexos definidos pelo usuário. Os desenvolvedores usam Solidity para escrever smart contracts que governam o comportamento de contas e aplicações na blockchain. A sintaxe da linguagem é semelhante a JavaScript e C++, tornando-a relativamente acessível para programadores familiarizados com essas linguagens. O código Solidity é compilado em bytecode, que é então implantado e executado na EVM.
Os recursos do Solidity incluem suporte para variáveis de estado, funções, eventos e modificadores. Ele também fornece funções criptográficas embutidas e acesso aos dados da blockchain. No entanto, os smart contracts Solidity são imutáveis após a implantação, por isso, planejamento cuidadoso e testes completos são cruciais para evitar vulnerabilidades. Auditorias de segurança e verificação formal são práticas comuns para mitigar riscos.
graph LR
Center["Solidity"]:::main
Pre_javascript["javascript"]:::pre --> Center
click Pre_javascript "/terms/javascript"
Pre_smart_contract["smart-contract"]:::pre --> Center
click Pre_smart_contract "/terms/smart-contract"
Rel_ethereum["ethereum"]:::related -.-> Center
click Rel_ethereum "/terms/ethereum"
Rel_smart_contract_architecture["smart-contract-architecture"]:::related -.-> Center
click Rel_smart_contract_architecture "/terms/smart-contract-architecture"
Rel_java["java"]:::related -.-> Center
click Rel_java "/terms/java"
classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
linkStyle default stroke:#4b5563,stroke-width:2px;
🧠 Teste de conhecimento
🧒 Explique como se eu tivesse 5 anos
📜 Solidity is a special code language used to write 'digital rules' for the world's computer ([Ethereum](/pt/terms/ethereum)). It's like writing a contract that nobody can cheat on because the computer follows the rules exactly as they are written.
🤓 Expert Deep Dive
Solidity's design prioritizes deterministic execution within the EVM, crucial for consensus. Its static typing catches many errors at compile time, reducing runtime surprises. The language's object-oriented features, while convenient, introduce complexities in inheritance and state management that can lead to subtle bugs if not managed carefully. Gas optimization is a primary concern; inefficient Solidity code can lead to prohibitively expensive transactions. The compiler itself is a critical component, and its evolution (e.g., introduction of Yul IR, optimizer improvements) significantly impacts gas costs and security. [Formal verification tools](/pt/terms/formal-verification-tools) are increasingly important for auditing Solidity contracts due to the high stakes of immutable, on-chain logic.