Search Your Query

All Cart

Cart

  • Home
  • Solidity Programming for Beginners: Deploy Your First Smart Contract in Remix

Solidity Programming for Beginners: Deploy Your First Smart Contract in Remix

images images

TL;DR

  • Solidity programming is how you write smart contracts that run on Ethereum. You do not need to install anything to start: Remix IDE runs in your browser.
  • You will write two contracts: a minimal HelloWorld with a state variable, and a working ERC-20 token using OpenZeppelin.
  • Every deploy costs gas. Use a testnet and faucet funds, never real ETH, until your code is tested.
  • The three beginner killers are reentrancy, missing access control, and storage-vs-memory confusion. Fix them before you deploy anything holding value.

What You Need Before You Start

Solidity programming sounds intimidating because the stakes are high. A bug in a normal app gets patched. A bug in a deployed contract can drain funds permanently, because deployed code cannot be quietly changed.

That is the whole reason to start small. A “Hello World” contract teaches the full loop: write, compile, deploy, and call. The mechanics are the same for a token, an NFT, or a lending market. Only the logic in the middle grows.

You need three things to begin.

  • Remix IDE: a free, browser-based editor at remix.ethereum.org. No installation, no command line.
  • A browser wallet: MetaMask is the standard choice. You only need it when deploying to a public test network.
  • Test ETH: free tokens from a faucet to pay gas on a testnet. Sepolia is the recommended default test network for application development.

Do not use a wallet that holds real funds for development. Create a fresh MetaMask account and keep it separate.

Solidity in one paragraph

Solidity is a statically typed, contract-oriented language that compiles to EVM bytecode. Its syntax borrows from JavaScript, C++, and Python. Variables have explicit types like uint256, bool, address, and string. Code is organized into contract blocks that resemble classes.

The latest stable release is 0.8.37, published in September 2026. Solidity 0.8 and later includes automatic overflow checks, so you do not need a separate SafeMath library for basic arithmetic.

Step-by-Step Setup in Remix IDE

Remix is the fastest path from zero to a deployed contract. It compiles and deploys in the browser, and it resolves imports like OpenZeppelin automatically.

Write your first contract

  1. Go to remix.ethereum.org.
  2. In the File Explorer panel on the left, click the new file icon.
  3. Name the file HelloWorld.sol. Remix appends .sol if you omit it.
  4. Paste the following code into the editor.

solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract HelloWorld {
    string public greet = "Hello, World!";
}

Every line has a job.

  • // SPDX-License-Identifier: MIT declares the license. The compiler warns if it is missing.
  • pragma solidity ^0.8.0; locks the compiler to 0.8.x. The caret allows any compatible 0.8 release but rejects a breaking 0.9.0.
  • contract HelloWorld { ... } declares the contract, similar to a class.
  • string public greet = "Hello, World!"; stores a string on-chain. The public keyword generates a free getter, so anyone can read greet without you writing a function.
Remix File Explorer with HelloWorld.sol created and the code pasted into the editor

Compile and deploy

  1. Click the Solidity Compiler tab in the left sidebar. It is the second icon.
  2. Select a compiler version that matches your pragma, such as 0.8.37.
  3. Click Compile HelloWorld.sol. A green checkmark confirms success.
  4. Click the Deploy & Run Transactions tab. It is the third icon.
  5. In the Environment dropdown, choose Remix VM. This is a simulated blockchain in your browser with 10 pre-funded accounts, each holding 100 ether.
  6. Click Deploy. No wallet confirmation is needed on Remix VM.
  7. Expand the deployed contract under Deployed Contracts and click greet. It returns Hello, World!.

That is the full loop. You compiled Solidity to bytecode, deployed it to a simulated chain, and read state from it.

Make it interactive

A fixed string is a start, but contracts become useful when state can change. Add one function.

solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract HelloWorld {
    string public greet = "Hello, World!";

    function setGreeting(string memory _newGreeting) public {
        greet = _newGreeting;
    }
}

Recompile and redeploy. Under Deployed Contracts, you now see two buttons: greet (blue, read-only) and setGreeting (orange, writes state).

Reading greet is free. Calling setGreeting changes on-chain state, so it costs gas and requires a transaction. That distinction between reading and writing is the single most important concept in Ethereum development.

Your First Real Result: A Working ERC-20 Token

The Hello World contract proves the workflow. An ERC-20 token proves you can use Solidity programming for something people actually build. ERC-20 is the standard interface for fungible tokens, and OpenZeppelin provides audited, reusable implementations so you do not rewrite the basics.

Create the token contract

  1. In Remix, create a new file called MyToken.sol.
  2. Paste the following contract.

solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.35;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor(uint256 initialSupply)
        ERC20("MyToken", "MTK")
    {
        _mint(msg.sender, initialSupply * 10 ** decimals());
    }
}

This imports the full ERC-20 implementation from OpenZeppelin and mints an initial supply to the deployer. The name is “MyToken” and the symbol is “MTK”. Change both to whatever you want.

Deploy the token

  1. Compile MyToken.sol in the Solidity Compiler tab.
  2. Open Deploy & Run Transactions.
  3. In the Deploy field, enter an initial supply, for example 1000000 for one million tokens.
  4. Click Deploy and confirm the transaction if you are using an injected wallet.
  5. Under Deployed Contracts, expand MyToken and call name, symbol, totalSupply, and balanceOf with your address. The values should match what you configured.
Remix Deploy panel showing MyToken selected with an initial supply entered and the Deploy button ready

Deploy to a public testnet

Remix VM resets when you refresh the browser. For a more realistic test, deploy to Sepolia.

  1. Install MetaMask and switch the network to Sepolia.
  2. Claim free Sepolia ETH from a faucet.
  3. In Remix, set Environment to Injected Provider – MetaMask.
  4. Confirm that the account shown in Remix matches your MetaMask address.
  5. Deploy the contract and approve the transaction in MetaMask.
  6. Wait for confirmation, then copy the contract address from the Deployed Contracts panel and look it up on a Sepolia block explorer.

If the deploy button does nothing, check that MetaMask is unlocked and connected to the correct network.

Mistakes, Safety, and Best Practices

Solidity programming rewards precision. Most beginner losses do not come from exotic exploits. They come from a handful of repeated errors that are well documented and preventable.

Mistake 1: Reentrancy from updating state after an external call

A reentrancy attack happens when a malicious contract calls back into your function before your balance update completes. If you send ETH before setting the balance to zero, the attacker can withdraw repeatedly.

Vulnerable pattern:

solidity

payable(msg.sender).call{value: bal}("");
deposit[msg.sender] = 0; // too late

Safe pattern: apply Checks-Effects-Interactions.

solidity

deposit[msg.sender] = 0; // effect first
(bool success, ) = payable(msg.sender).call{value: bal}("");
require(success, "transfer failed");

Use OpenZeppelin’s ReentrancyGuard with the nonReentrant modifier as a second layer of defense. Check first, update state second, interact with external addresses last.

Mistake 2: Missing access control on mint and admin functions

If a mint function is public with no restriction, anyone can create tokens for themselves. That is not a bug in the compiler. It is a missing permission check.

Use an onlyOwner modifier or OpenZeppelin AccessControl:

solidity

modifier onlyOwner() {
    require(msg.sender == owner, "not admin");
    _;
}

Set owner = msg.sender in the constructor and protect every privileged function.

Mistake 3: Confusing storage with memory

Local variables of struct or array type default to memory, which is a copy. Changing the copy does not change the on-chain data. Beginners often “update” a struct and wonder why nothing persists.

Use storage when you need to modify persistent state:

solidity

User storage temp = user;
temp.name = newName; // writes to storage

Use calldata for external function parameters that do not need modification. It is cheaper than memory because it references the input directly.

Mistake 4: Using transfer() for ETH payouts

transfer() forwards a fixed 2300 gas stipend. If the recipient is a contract with logic in its receive function, the transfer reverts and your ETH can be stuck. Prefer call{value: ...}("") with a success check.

Safety note: This article is educational only and is not financial advice. Smart contracts carry permanent risk. Never deploy code holding real funds without testing, and consider a professional audit before launch.

FAQ

Do I need to install anything to start Solidity programming?
No. Remix IDE runs entirely in your browser and includes a compiler and a simulated blockchain. You only need MetaMask when you deploy to a public test network.

What is the difference between Remix, Hardhat, and Foundry?
Remix is best for first contracts and quick experiments. Hardhat is a local development environment for scripted deployments and automated tests. Foundry is a Rust-based toolchain for fast test suites and larger codebases.

How much does it cost to deploy a smart contract?
On a testnet, it costs nothing real. On Ethereum mainnet, deployment costs gas paid in ETH. The exact amount depends on bytecode size and network conditions. Always test on Sepolia first.

Is Solidity the same as JavaScript?
No. Solidity borrows syntax from JavaScript, but it is statically typed, compiled to bytecode, and runs on the EVM. Concepts like gas, storage, and msg.sender have no direct JavaScript equivalent.

What version of Solidity should I use?
Use the latest stable 0.8.x release. Version 0.8 includes built-in overflow checks, which removes the need for SafeMath in most cases. Pin the pragma to a compatible range such as ^0.8.30.

Once your solidity programming setup is working, the next step is to move beyond Remix. Hardhat or Foundry gives you automated tests, and OpenZeppelin gives you audited building blocks. Keep your test wallet separate, test on Sepolia, and read every line before you deploy. For more developer guides, explore packprotv.com.