
Smart Contract Development 101
Write, test, and deploy your first smart contract with Solidity - complete walkthrough from Remix IDE to mainnet deployment.
Smart Contract Development 101
Smart contracts are self-executing programs stored on the blockchain. This guide walks you through writing, testing, and deploying your first smart contract on Ethereum using Solidity.
A simple storage contract that lets users:
- Store and retrieve a number on-chain
- Increment and decrement that number
- Track who last updated the value
NOTEPrerequisites: Basic programming knowledge (variables, functions, types). No blockchain experience required.
Remix is a browser-based IDE - no installation needed.
- Go to remix.ethereum.org
- You will see a file explorer, editor, and terminal
- Create a new file called
Storage.sol
bashmkdir my-first-contract cd my-first-contract npm init -y npm install --save-dev hardhat @nomicfoundation/hardhat-toolbox npx hardhat init # Choose "Create a JavaScript project"
solidity// SPDX-License-Identifier: MIT pragma solidity ^0.8.19; contract SimpleStorage { // State variable - stored permanently on-chain uint256 private storedNumber; // Track who last interacted address public lastUpdater; // Event - logged on-chain for frontends to listen to event NumberChanged(uint256 newValue, address changedBy); // Store a new number function set(uint256 _number) public { storedNumber = _number; lastUpdater = msg.sender; emit NumberChanged(_number, msg.sender); } // Retrieve the stored number function get() public view returns (uint256) { return storedNumber; } // Increment by 1 function increment() public { storedNumber += 1; lastUpdater = msg.sender; emit NumberChanged(storedNumber, msg.sender); } // Decrement by 1 (with safety check) function decrement() public { require(storedNumber > 0, "Already zero - cannot decrement"); storedNumber -= 1; lastUpdater = msg.sender; emit NumberChanged(storedNumber, msg.sender); } }
| Component | Purpose | |---|---| |
pragma solidity ^0.8.19contract SimpleStorageuint256 private storedNumbermsg.sendervieweventrequire()- Click the Solidity Compiler tab (left sidebar, S icon)
- Select compiler version
0.8.19 - Click Compile Storage.sol
- Green checkmark = success
- Click the Deploy & Run tab (Ethereum logo icon)
- Under "Environment", select Injected Provider - MetaMask
- Make sure MetaMask is connected to Sepolia testnet
- Click the orange Deploy button
- Confirm the transaction in MetaMask
- Wait ~15 seconds for confirmation
Once deployed, your contract appears under "Deployed Contracts":
- Click → enter a number → confirm → check
setto verifyget - Click → confirm → the number increases by 1
increment - Click → shows your wallet address
lastUpdater
Testnets let you deploy and test for free using test ETH:
| Network | Faucet | |---|---| | Sepolia (Ethereum) | sepoliafaucet.com | | Goerli (Ethereum) | goerlifaucet.com | | Mumbai (Polygon) | mumbaifaucet.com |
Never deploy to mainnet until you have tested on a testnet first.
Every operation on Ethereum costs gas:
| Operation | Approximate Gas | |---|---| | Simple transfer (ETH) | 21,000 | | Token transfer (ERC-20) | ~45,000 | | Deploy simple contract | ~150,000-300,000 | | Complex DeFi interaction | 100,000-500,000 |
Gas price fluctuates with network demand. Use etherscan.io/gastracker to check current rates.
Cost formula:
Gas used x Gas price (in gwei) = Total cost in ETHsoliditybool public isActive; // true or false uint256 public balance; // unsigned integer (0 to 2^256-1) int256 public temperature; // signed integer address public owner; // Ethereum address (20 bytes) string public name; // text string bytes32 public hash; // fixed-size byte array // Mappings (like dictionaries/hashmaps) mapping(address => uint256) public balances; // Arrays uint256[] public numbers; address[] public whitelist; // Structs (custom types) struct User { string name; uint256 age; bool isActive; } mapping(address => User) public users;
| Modifier | Who Can Call | |---|---| |
publicexternalinternalprivatesolidity// Custom access control modifier onlyOwner() { require(msg.sender == owner, "Not the owner"); _; // Continue executing the function } function withdraw() public onlyOwner { // Only the owner can call this payable(owner).transfer(address(this).balance); }
Foundry is a fast testing framework written in Solidity:
bash# Install Foundry curl -L https://foundry.paradigm.xyz | bash foundryup # Create test file: test/Storage.t.sol
solidity// SPDX-License-Identifier: MIT pragma solidity ^0.8.19; import "forge-std/Test.sol"; import "../src/Storage.sol"; contract StorageTest is Test { SimpleStorage public storage; function setUp() public { storage = new SimpleStorage(); } function testSetAndGet() public { storage.set(42); assertEq(storage.get(), 42); } function testIncrement() public { storage.set(10); storage.increment(); assertEq(storage.get(), 11); } function testDecrementRevertsAtZero() public { storage.set(0); vm.expectRevert("Already zero - cannot decrement"); storage.decrement(); } }
bashforge test # Run all tests forge test -vvv # Verbose output forge coverage # Line coverage report
NOTE80% of smart contract hacks come from the same 5 vulnerability types.
- Reentrancy: Always update state before making external calls
- Integer overflow: Solidity 0.8+ protects by default
- Access control: Use or OpenZeppelin
onlyOwnerOwnable - Front-running: Use commit-reveal patterns for sensitive operations
- Oracle manipulation: Never use spot DEX prices as oracles
Use OpenZeppelin contracts instead of writing your own:
solidityimport "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; contract MyToken is ERC20, Ownable, ReentrancyGuard { constructor() ERC20("MyToken", "MTK") { _mint(msg.sender, 1_000_000 * 10**decimals()); } }
When you are ready for real ETH:
- Get audited by a reputable firm (Trail of Bits, OpenZeppelin, Consensys Diligence)
- Launch a bug bounty on Immunefi
- Use a multisig wallet (Safe) for admin control
- Deploy via a deployment script, not Remix
- Verify your contract on Etherscan for transparency
- Complete this tutorial - deploy to Sepolia testnet
- Build an ERC-20 token using OpenZeppelin
- Build an ERC-721 NFT collection
- Study the Solidity docs
- Complete challenges on CryptoZombies
- Compete in Code4rena audit contests
- Contribute to open-source protocols
Happy building! Remember: test everything, respect user funds, and get audited.
Found this guide helpful? Share it with others

