0Pricing
Blockchain Smart Contracts with Solidity · Lezione

Il primo contratto Solidity

Scriva e compili un semplice smart contract "Hello World" utilizzando Remix IDE e acquisisca esperienza pratica con la sintassi di Solidity.

Il primo contratto Solidity è una lezione Blockchain Smart Contracts with Solidity gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Blockchain Smart Contracts with Solidity, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Blockchain Smart Contracts with Solidity include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

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!

Domande Frequenti

La lezione «Il primo contratto Solidity» è gratuita?

Sì — il testo completo di «Il primo contratto Solidity» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Blockchain Smart Contracts with Solidity, passa a CoddyKit PRO. Il corso Blockchain Smart Contracts with Solidity include 4 lezioni in totale.

Cosa imparerò in «Il primo contratto Solidity»?

Scriva e compili un semplice smart contract "Hello World" utilizzando Remix IDE e acquisisca esperienza pratica con la sintassi di Solidity. Eserciti Blockchain Smart Contracts with Solidity con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Blockchain Smart Contracts with Solidity?

Non è richiesta alcuna esperienza precedente. Blockchain Smart Contracts with Solidity su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.

Quanto tempo richiede la lezione «Il primo contratto Solidity»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Blockchain Smart Contracts with Solidity?

Sì. Ogni lezione Blockchain Smart Contracts with Solidity include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Che cos'è la tecnologia blockchain?
  2. Fondamenti di Ethereum ed EVM
  3. Il primo contratto Solidity
  4. Wallet, chiavi e transazioni
← Torna a Blockchain Smart Contracts with Solidity