最初のSolidityコントラクト
Remix IDEを使ってシンプルな「Hello World」スマートコントラクトを記述・コンパイルし、Solidity構文を実際に体験します。
「最初のSolidityコントラクト」はCoddyKit上の無料Blockchain Smart Contracts with Solidityレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはBlockchain Smart Contracts with Solidity学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Blockchain Smart Contracts with Solidityコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Your First Smart Contract!
Time to write your first smart contract! We'll build a simple Hello World in Solidity using the browser-based Remix IDE - no setup needed.
Meet Remix IDE
Remix IDE lets you write, compile, debug, and deploy Solidity contracts right in your browser. It's perfect for learning and quick prototyping.
Solidity Version Pragma
Every Solidity file opens with a pragma that pins the compiler version. The code below means versions 0.8.0 up to (but not including) 0.9.0 are allowed.
pragma solidity ^0.8.0;Defining Your Contract
Solidity code lives inside a contract, much like a class in OOP. You declare it with the contract keyword, a name, and curly braces, as shown.
contract MyFirstContract {
// Your contract's code goes here
}Adding a State Variable
A state variable is stored permanently on chain and defines your contract's state. Here we add a string called greeting; public makes it readable by anyone.
contract MyFirstContract {
string public greeting;
}The Constructor Function
The constructor runs exactly once, at deployment, to initialize state. Here it sets greeting to "Hello CoddyKit!" the moment the contract goes live.
contract MyFirstContract {
string public greeting;
constructor() {
greeting = "Hello CoddyKit!";
}
}Writing a View Function
A view function reads contract state without changing it. This getGreeting is public and returns a string from memory, as shown below.
contract MyFirstContract {
string public greeting;
constructor() {
greeting = "Hello CoddyKit!";
}
function getGreeting() public view returns (string memory) {
return greeting;
}
}Our Full 'Hello World' Contract
Here's the full Hello World contract. Paste it into Remix, compile, deploy to a test chain, then call getGreeting() to see it work.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleGreeting {
string public greeting;
constructor() {
greeting = "Hello CoddyKit!";
}
function getGreeting() public view returns (string memory) {
return greeting;
}
}Compiling Your Contract
Before deploying, a contract must be compiled - turning your Solidity into EVM bytecode. Remix has a built-in compiler with a handy Auto compile option.
Quick Check: Contract Structure
Which part of a Solidity smart contract specifies the minimum compatible compiler version?
Recap: Your First Contract
Recap: you built a Solidity contract with a pragma, a contract block, a state variable, a constructor, and a view function - all in Remix. Nice work!
よくある質問
「最初のSolidityコントラクト」レッスンは無料ですか?
はい。「最初のSolidityコントラクト」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Blockchain Smart Contracts with Solidityコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Blockchain Smart Contracts with Solidityコースには全4レッスンが含まれています。
「最初のSolidityコントラクト」で何を学びますか?
Remix IDEを使ってシンプルな「Hello World」スマートコントラクトを記述・コンパイルし、Solidity構文を実際に体験します。 ブラウザで直接実行するハンズオンコードでBlockchain Smart Contracts with Solidityを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Blockchain Smart Contracts with Solidityを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのBlockchain Smart Contracts with Solidityは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「最初のSolidityコントラクト」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このBlockchain Smart Contracts with Solidityレッスンでコードを書いて実行できますか?
はい。すべてのBlockchain Smart Contracts with Solidityレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- ブロックチェーン技術とは
- Ethereumの基礎とEVM
- 最初のSolidityコントラクト
- ウォレット、鍵、トランザクション