TP Ethereum Blockchain - Part I

Premières transactions

Objective: Create your first Wallet and perform your first ETH transactions on a test network.

  • Install the Metamask extension in your browser (Chrome or Firefox)
  • Create an account and copy to a sheet (or save) the twelve words.
  • Connect Metamask to the Goerli test network.
  • Retrieve some ETH via one faucet.
  • Monitor via the blockchain explorer (etherscan) for transaction confirmation.
  • Send all your ETH to a friend. Why is the transaction rejected?
  • Send few ETH to another account belonging to you (You will have to create it first) or a friend's account.

Work due:

  1. When you send all your ETH why was the transaction rejected or the recipient did not receive exactly all your ETH?
  2. How much does it cost in GAS and then in Ether (or GWei) to send Ether (simple transaction of ETH from one account to another)?
  3. Are the fees in GAS proportional to the amount of Ether sent?

First interaction with the Ethereum blockchain

Objective: Make your first request on the mainnet.
- Create an account on infura (save your login)
- Make a curl request to find out the number of the last block mined on the mainnet.

Useful link : https://eth.wiki/json-rpc/API#eth_blocknumber

Work due:

  1. What is the number of the last block mined in decimal on the mainnet (note the date and time of reading)?

First Smart Contract

Objective: Compile and deploy a first Smart Contract on a test network.

  • Copy/paste the Smart Contract (Hello.sol) in Solidity provided below into the Remix IDE (https://remix.ethereum.org).
  • Compile and deploy the Smart Contract on the Goerli network (Injected Web3 / Goerli).
  • How much did it cost to deploy the contract? Does its size influence the cost?
  • Find the address of the contract on Etherscan (goerli). What is the process?
  • Try to modify the string message. How much does it cost ?
  • Write a contract similar to Hello.sol to handle this time an integer uint256.
pragma solidity ^0.5.7;

contract Hello {
  string private message;
  constructor(string memory _message) public {
    message = _message;
  }
  function getMessage() public view returns (string memory) {
    return message;
  }
  function setMessage(string memory _message) public {
    message = _message;
  }
}

Simple Smart Contract

Objective: Create a first Token based on a simple contract.

  • Read, understand and deploy on a test network (Goerli) the contract below.
  • Who is the initial owner of the tokens?
  • Transfer some tokens from one account to another.
  • View the number of tokens belonging to each account on www.myetherwallet.com (the number of decimal is 0) or MyCrypto.com.
pragma solidity >=0.4.22 <0.6.0;

contract MyToken {
    /* This creates an array with all balances */
    mapping (address => uint256) public balanceOf;

    /* Initializes contract with initial supply tokens to the creator of the contract */
    constructor( uint256 initialSupply ) public {
        balanceOf[msg.sender] = initialSupply;
    }

    /* Send coins */
    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);           // Check if the sender has enough
        require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
        balanceOf[msg.sender] -= _value;                    // Subtract from the sender
        balanceOf[_to] += _value;                           // Add the same to the recipient
        return true;
    }
}