Session 2: Building with Remix IDE

Creating and deploying your first smart contract using Remix Ethereum IDE

Learning Objectives

  • Understand Solidity syntax and structure
  • Learn how to use Remix Ethereum IDE
  • Create and deploy a simple smart contract
  • Test and debug smart contracts
  • Understand contract security considerations

1. Introduction to Solidity (25 min)

We'll cover the basics of Solidity programming language, including data types, functions, modifiers, events, and error handling.

Key Topics:

  • Solidity data types and variables
  • Functions and visibility
  • Modifiers and events
  • Error handling and require statements

Add Your Content Here:

Add code examples, explanations, or diagrams about Solidity basics here.

Slide 1 of 5

Resources

Remix Ethereum IDE

Open Remix IDE

Session Materials

Sample ERC-20 Token Contract

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

contract SimpleToken {
    string public name;
    string public symbol;
    uint8 public decimals;
    uint256 public totalSupply;
    
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;
    
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    
    constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _initialSupply) {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;
        totalSupply = _initialSupply * 10**uint256(_decimals);
        balanceOf[msg.sender] = totalSupply;
        emit Transfer(address(0), msg.sender, totalSupply);
    }
    
    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value, "Insufficient balance");
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(msg.sender, _to, _value);
        return true;
    }
    
    function approve(address _spender, uint256 _value) public returns (bool success) {
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }
    
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(balanceOf[_from] >= _value, "Insufficient balance");
        require(allowance[_from][msg.sender] >= _value, "Insufficient allowance");
        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        allowance[_from][msg.sender] -= _value;
        emit Transfer(_from, _to, _value);
        return true;
    }
}

Exercises

Exercise 1: Create a Simple Storage Contract

Using Remix IDE, create a contract that can store and retrieve a string value. Include functions to set and get the value.

Hint: Use a public state variable and create setter/getter functions.

Exercise 2: Extend the Token Contract

Modify the sample ERC-20 token contract to add a function that allows the owner to mint new tokens.

Hint: Add an owner variable and a modifier to restrict access to certain functions.

Exercise 3: Deploy and Test

Deploy your token contract to the Remix VM environment and test all its functions. Document any issues you encounter.

Hint: Use different accounts in Remix to test transfer functionality between users.