# Remix IDE Walkthrough ## What is Remix? Remix is an Integrated Development Environment (IDE), or a place where programmers can write and test their code efficiently. Remix is specialized for developing, deploying, and administering smart contracts on the blockchain, specifically using Ethereum. Remix uses Solidity for its code, an object-oriented, high-level language that is designed for smart contract implementation. Solidity has syntax and features similar to C++ and Java. The Remix documentation, a comprehensive and in-depth guide for learning Remix, is linked below. [Remix Documentation](https://remix-ide.readthedocs.io/en/latest/) ## Video Walkthrough <!--[Youtube](https://youtu.be/tabTcALTDEg)--> <iframe width="560" height="315" src="https://www.youtube.com/embed/tabTcALTDEg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> #### Follow along with the code: ```solidity= // works without tries: // SPDX-License-Identifier: MIT pragma solidity >=0.5.0 <0.9.0; contract GuessingGame { uint private randomNum; uint private tries = 0; constructor() public { randomNum = uint(blockhash(block.number-1)) % 100; } function createRandom() public { randomNum = uint(blockhash(block.number-1)) % 100; } function message() public { tries++; } function guess(uint num) public view returns (string memory) { int diff = int(num) - int(randomNum); if (diff == 0) { return "Correct! You got it in x tries!"; } else if (diff > 0) { return "Wrong! Guess lower!"; } else { return "Wrong! Guess higher!"; } } } ``` ## Different Sections of Remix The most common layout of Remix consists of the icon panel (skinny column on the left side), side panel (thicker column next to the icon panel), main panel (section taking up most of the screen), and the terminal (section below the main panel). ![](https://i.imgur.com/4hHimjy.png) These different sections serve specific purposes: - Icon Panel - Choosing what plugin appears in the side panel - Side Panel - GUI of most plugins appear here - Main Panel - Place to edit files - Terminal - Where to view the results of interactions with GUI and run scripts *Different themes can be applied at the bottom of the settings plugin.* ## Sample Programs ### Fundamental program ```solidity= pragma solidity >=0.7.0 <0.9.0; /** * @title Storage * @dev Store & retrieve value in a variable * @custom:dev-run-script ./scripts/deploy_with_ethers.ts */ contract Storage { uint256 number; /** * @dev Store value in variable * @param num value to store */ function store(uint256 num) public { number = num; } /** * @dev Return value * @return value of 'number' */ function retrieve() public view returns (uint256){ return number; } } ``` #### What does this program do? This program is a simple process where one is able to enter a number and store it as a uint256. Another function called `retrieve`, returns the number that you input using `store`. This is probably the most simple smart contracts can get but it also should give you an idea that smart contracts are not some completely alien-like form of technology. There are several different uses of smart contracts and we will show you another more complex smart contract in the next example program. ### More complex program ```solidity= pragma solidity ^0.4.17; contract Auction { struct Item { uint itemId; // id of the item uint[] itemTokens; //tokens bid in favor of the item } struct Person { uint remainingTokens; // tokens remaining with bidder uint personId; // it serves as tokenId as well address addr;//address of the bidder } mapping(address => Person) tokenDetails; //address to person Person [4] bidders;//Array containing 4 person objects Item [3] public items;//Array containing 3 item objects address[3] public winners;//Array for address of winners address public beneficiary;//owner of the smart contract uint bidderCount=0;//counter function Auction() public payable{ beneficiary = msg.sender; uint[] memory emptyArray; items[0] = Item({itemId:0,itemTokens:emptyArray}); items[1] = Item({itemId:1,itemTokens:emptyArray}); items[2] = Item({itemId:2,itemTokens:emptyArray}); } function register() public payable{ bidders[bidderCount].personId = bidderCount; bidders[bidderCount].addr = msg.sender; bidders[bidderCount].remainingTokens = 5; // only 5 tokens tokenDetails[msg.sender]=bidders[bidderCount]; bidderCount++; } function bid(uint _itemId, uint _count) public payable{ if (tokenDetails[msg.sender].remainingTokens < _count || tokenDetails[msg.sender].remainingTokens == 0) {revert();} if (_itemId > 2) {revert();} uint balance = tokenDetails[msg.sender].remainingTokens - _count; tokenDetails[msg.sender].remainingTokens=balance; bidders[tokenDetails[msg.sender].personId].remainingTokens=balance;//updating the same balance in bidders map. Item storage bidItem = items[_itemId]; for(uint i=0; i<_count;i++) { bidItem.itemTokens.push(tokenDetails[msg.sender].personId); } } modifier onlyOwner { require(beneficiary == msg.sender); _; } function revealWinners() public onlyOwner{ for (uint id = 0; id < 3; id++) { Item storage currentItem=items[id]; if(currentItem.itemTokens.length != 0){ uint randomIndex = (block.number / currentItem.itemTokens.length)% currentItem.itemTokens.length; uint winnerId = currentItem.itemTokens[randomIndex]; winners[id] = bidders[winnerId].addr; } } } } ``` #### What does this program do? This program is a replication of an auction. It has a list of users, items, etc. Specifically, we see in the person array that there are 4 players. The functions replicate the processes of an actual auction.