Solidity入門
pragmaやcontractキーワードを含め、Solidityの構文、構造、基本的なコントラクト宣言について概観します。
「Solidity入門」はCoddyKit上の無料Web3 & DApp Development Fundamentalsレッスンです。 これはレッスン1/3です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはWeb3 & DApp Development Fundamentals学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Web3 & DApp Development Fundamentalsコースには全3レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Meet Solidity: Language of Smart Contracts
Welcome to Solidity! It's the primary language for writing smart contracts on blockchain platforms like Ethereum.
Think of smart contracts as self-executing agreements stored on a blockchain. Learning Solidity opens the door to building decentralized applications (DApps).
Why Solidity Matters
Solidity is a high-level, object-oriented language. It's specifically designed to implement business logic for DApps.
It enables you to create digital tokens, build decentralized finance (DeFi) protocols, and manage digital assets securely on a blockchain.
Your First Solidity File
Every Solidity smart contract lives in a file ending with the .sol extension.
- Just like a
.jsfile for JavaScript. - Or a
.pyfile for Python. - The first line of a Solidity file often defines the compiler version to be used.
The Pragma Directive
The pragma directive is crucial. It tells the Solidity compiler which version to use for your contract.
For example, pragma solidity ^0.8.0; means "use any compiler version from 0.8.0 up to, but not including, 0.9.0."
This ensures your contract compiles predictably and avoids unexpected behavior from future compiler changes.
Declaring a Contract
In Solidity, the fundamental building block for your smart contract is the contract keyword.
- It's similar to a "class" in object-oriented programming languages.
- Your entire smart contract's logic, including variables and functions, will live inside a
contractblock.
Our First Basic Contract
Let's put pragma and contract together. This is the most basic, yet complete, Solidity contract you can write.
It doesn't do much yet, but it's ready to be compiled and deployed!
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MyFirstContract {
// This contract is currently empty!
}Comments in Solidity
Comments help explain your code to others and your future self. They are ignored by the compiler.
- Single-line comments start with
//. - Multi-line comments are enclosed by
/*and*/. - The
SPDX-License-Identifieris a special comment used to specify the contract's license.
Contract Name & Structure
Contract names usually start with an uppercase letter, following common programming conventions (e.g., MyFirstContract).
The code inside the curly braces {} defines the contract's logic. This is where you'll add state variables, functions, and events as you learn more.
Quick Check: Pragma Purpose
The pragma solidity ^0.8.0; line is essential for smart contract development. What is its primary role?
Recap: Your Solidity Journey Begins!
You've learned the very basics of Solidity!
- We covered the
.solfile extension. - The critical
pragmadirective for compiler versions. - The fundamental
contractkeyword. - How to add comments for code clarity.
Next, we'll dive deeper into variables and data types!
よくある質問
「Solidity入門」レッスンは無料ですか?
はい。「Solidity入門」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Web3 & DApp Development Fundamentalsコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Web3 & DApp Development Fundamentalsコースには全3レッスンが含まれています。
「Solidity入門」で何を学びますか?
pragmaやcontractキーワードを含め、Solidityの構文、構造、基本的なコントラクト宣言について概観します。 ブラウザで直接実行するハンズオンコードでWeb3 & DApp Development Fundamentalsを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Web3 & DApp Development Fundamentalsを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのWeb3 & DApp Development Fundamentalsは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/3です。
「Solidity入門」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このWeb3 & DApp Development Fundamentalsレッスンでコードを書いて実行できますか?
はい。すべてのWeb3 & DApp Development Fundamentalsレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。