Su primer contrato de Solidity
Escriba y compile un smart contract sencillo de «Hello World» con Remix IDE y adquiera experiencia práctica con la sintaxis de Solidity.
Su primer contrato de Solidity es una lección gratuita de Blockchain Smart Contracts with Solidity en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Blockchain Smart Contracts with Solidity, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Blockchain Smart Contracts with Solidity incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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
¿Qué parte de un contrato inteligente de Solidity especifica la versión mínima de compilador compatible?
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!
Preguntas frecuentes
¿La lección «Su primer contrato de Solidity» es gratis?
Sí — el texto completo de «Su primer contrato de Solidity» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Blockchain Smart Contracts with Solidity, actualiza a CoddyKit PRO. El curso de Blockchain Smart Contracts with Solidity incluye 4 lecciones en total.
¿Qué aprenderé en «Su primer contrato de Solidity»?
Escriba y compile un smart contract sencillo de «Hello World» con Remix IDE y adquiera experiencia práctica con la sintaxis de Solidity. Practicas Blockchain Smart Contracts with Solidity con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Blockchain Smart Contracts with Solidity?
No se requiere experiencia previa. Blockchain Smart Contracts with Solidity en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.
¿Cuánto tiempo toma la lección «Su primer contrato de Solidity»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Blockchain Smart Contracts with Solidity?
Sí. Cada lección de Blockchain Smart Contracts with Solidity incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- ¿Qué es la tecnología blockchain?
- Fundamentos de Ethereum y EVM
- Su primer contrato de Solidity
- Wallets, claves y transacciones