0Pricing
Blockchain Smart Contracts with Solidity · Урок

Ваш первый контракт Solidity

Напишите и скомпилируйте простой смарт-контракт «Hello World» с помощью Remix IDE и получите практический опыт работы с синтаксисом Solidity.

«Ваш первый контракт Solidity» — бесплатный урок Blockchain Smart Contracts with Solidity на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения 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/7) и разблокировать остальной курс Blockchain Smart Contracts with Solidity, подпишись на CoddyKit PRO. Курс Blockchain Smart Contracts with Solidity содержит 4 уроков всего.

Чему я научусь в уроке «Ваш первый контракт Solidity»?

Напишите и скомпилируйте простой смарт-контракт «Hello World» с помощью Remix IDE и получите практический опыт работы с синтаксисом Solidity. Ты практикуешь Blockchain Smart Contracts with Solidity с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Blockchain Smart Contracts with Solidity?

Предыдущий опыт не требуется. Blockchain Smart Contracts with Solidity на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.

Сколько времени занимает урок «Ваш первый контракт Solidity»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Blockchain Smart Contracts with Solidity?

Да. Каждый урок Blockchain Smart Contracts with Solidity включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Что такое технология блокчейна
  2. Основы Ethereum и EVM
  3. Ваш первый контракт Solidity
  4. Кошельки, ключи и транзакции
← Назад к Blockchain Smart Contracts with Solidity