From 7300267bde2f9015fce4655ef58ec01eb080be52 Mon Sep 17 00:00:00 2001 From: Kundan <131183962+CodeBlocker52@users.noreply.github.com> Date: Fri, 6 Oct 2023 22:28:08 +0530 Subject: [PATCH 1/4] Update DegenToken.sol --- contracts/DegenToken.sol | 85 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/contracts/DegenToken.sol b/contracts/DegenToken.sol index 73a9fc8..694056b 100644 --- a/contracts/DegenToken.sol +++ b/contracts/DegenToken.sol @@ -1,14 +1,85 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.18; +pragma solidity 0.8.17; -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; +contract DegenToken{ + address public owner; + uint public totalSupply; + mapping (address => uint) public balanceOf; -contract DegenToken is ERC20, Ownable { + event Transfer(address indexed from, address indexed to, uint amount); - constructor() ERC20("Degen", "DGN") {} + struct Item { + uint itemId; + string itemName; + uint itemPrice; + } + + mapping(uint => Item) public items; + uint public itemCount; + + constructor() { + owner = msg.sender; + totalSupply = 0; + } + + modifier onlyOwner { + require(msg.sender == owner, "You are not the Owner so you cant't Mint the Tokens"); + _; + } - function mint(address to, uint256 amount) public onlyOwner { - _mint(to, amount); + string public constant name = "Degen Token"; + string public constant symbol = "DGN"; + + function transfer(address _address, uint _value) external returns (bool) { + require(balanceOf[msg.sender] >= _value, "You don't have enough Tokens to Transfer"); + + balanceOf[msg.sender] -= _value; + balanceOf[_address] += _value; + + emit Transfer(msg.sender, _address, _value); + return true; + } + + function mint(address _address,uint _value) external onlyOwner { + balanceOf[_address] += _value; + totalSupply += _value; + emit Transfer(address(0), _address, _value); + } + + function burn(uint _value) external { + require(_value > 0, "You have Zero Tokens on the platform"); + require(balanceOf[msg.sender] >= _value, "You have less number of token then what you want to burn"); + balanceOf[msg.sender] -= _value; + totalSupply -= _value; + + emit Transfer(msg.sender, address(0), _value); + } + + function addItem(string memory _itemName, uint256 _itemPrice) external onlyOwner { + itemCount++; + Item memory newItem = Item(itemCount, _itemName, _itemPrice); + items[itemCount] = newItem; + } + + function getItems() external view returns (Item[] memory) { + Item[] memory allItems = new Item[](itemCount); + + for (uint i = 1; i <= itemCount; i++) { + allItems[i - 1] = items[i]; + } + + return allItems; + } + + function redeem(uint _itemId) external { + require(_itemId > 0 && _itemId <= itemCount, "Enterd Wrong number of Item!!"); + Item memory redeemedItem = items[_itemId]; + + require(balanceOf[msg.sender] >= redeemedItem.itemPrice, "You can't Redeem this Item as you have less no of Tokens then the Required!!"); + + balanceOf[msg.sender] -= redeemedItem.itemPrice; + balanceOf[owner] += redeemedItem.itemPrice; + emit Transfer(msg.sender, address(0), redeemedItem.itemPrice); + } } From 843574fbac241bbb68db6943446b39774b3482c6 Mon Sep 17 00:00:00 2001 From: Kundan <131183962+CodeBlocker52@users.noreply.github.com> Date: Fri, 6 Oct 2023 22:37:34 +0530 Subject: [PATCH 2/4] Update DegenToken.sol --- contracts/DegenToken.sol | 93 ++++++++++------------------------------ 1 file changed, 23 insertions(+), 70 deletions(-) diff --git a/contracts/DegenToken.sol b/contracts/DegenToken.sol index 694056b..9dad29a 100644 --- a/contracts/DegenToken.sol +++ b/contracts/DegenToken.sol @@ -1,85 +1,38 @@ // SPDX-License-Identifier: MIT -pragma solidity 0.8.17; +pragma solidity ^0.8.18; -contract DegenToken{ - address public owner; - uint public totalSupply; - mapping (address => uint) public balanceOf; +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; - event Transfer(address indexed from, address indexed to, uint amount); +contract DegenToken is ERC20, Ownable { - struct Item { - uint itemId; - string itemName; - uint itemPrice; - } - - mapping(uint => Item) public items; - uint public itemCount; + constructor() ERC20("Degen", "DGN") {} - constructor() { - owner = msg.sender; - totalSupply = 0; + // Mint new tokens. Only the owner can call this function. + function mint(address to, uint256 amount) public onlyOwner { + _mint(to, amount); } - modifier onlyOwner { - require(msg.sender == owner, "You are not the Owner so you cant't Mint the Tokens"); - _; + // Transfer tokens to another address. + function transferTokens(address to, uint256 amount) public { + _transfer(msg.sender, to, amount); } - string public constant name = "Degen Token"; - string public constant symbol = "DGN"; - - function transfer(address _address, uint _value) external returns (bool) { - require(balanceOf[msg.sender] >= _value, "You don't have enough Tokens to Transfer"); - - balanceOf[msg.sender] -= _value; - balanceOf[_address] += _value; - - emit Transfer(msg.sender, _address, _value); - return true; + // Redeem tokens for in-game items or rewards. + function redeemTokens(uint256 amount) public { + require(balanceOf(msg.sender) >= amount, "Insufficient balance"); + _burn(msg.sender, amount); + // Add logic here to provide in-game items or rewards. } - function mint(address _address,uint _value) external onlyOwner { - balanceOf[_address] += _value; - totalSupply += _value; - emit Transfer(address(0), _address, _value); + // Check the token balance of an address. + function checkTokenBalance(address account) public view returns (uint256) { + return balanceOf(account); } - function burn(uint _value) external { - require(_value > 0, "You have Zero Tokens on the platform"); - require(balanceOf[msg.sender] >= _value, "You have less number of token then what you want to burn"); - balanceOf[msg.sender] -= _value; - totalSupply -= _value; - - emit Transfer(msg.sender, address(0), _value); - } - - function addItem(string memory _itemName, uint256 _itemPrice) external onlyOwner { - itemCount++; - Item memory newItem = Item(itemCount, _itemName, _itemPrice); - items[itemCount] = newItem; - } - - function getItems() external view returns (Item[] memory) { - Item[] memory allItems = new Item[](itemCount); - - for (uint i = 1; i <= itemCount; i++) { - allItems[i - 1] = items[i]; - } - - return allItems; - } - - function redeem(uint _itemId) external { - require(_itemId > 0 && _itemId <= itemCount, "Enterd Wrong number of Item!!"); - Item memory redeemedItem = items[_itemId]; - - require(balanceOf[msg.sender] >= redeemedItem.itemPrice, "You can't Redeem this Item as you have less no of Tokens then the Required!!"); - - balanceOf[msg.sender] -= redeemedItem.itemPrice; - balanceOf[owner] += redeemedItem.itemPrice; - emit Transfer(msg.sender, address(0), redeemedItem.itemPrice); - + // Burn tokens owned by the caller. + function burnTokens(uint256 amount) public { + require(balanceOf(msg.sender) >= amount, "Insufficient balance"); + _burn(msg.sender, amount); } } From 28191ebf1017e6a150bad3626154733ba652c409 Mon Sep 17 00:00:00 2001 From: Kundan <131183962+CodeBlocker52@users.noreply.github.com> Date: Fri, 6 Oct 2023 22:42:52 +0530 Subject: [PATCH 3/4] Update README.md --- README.md | 57 ++++++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index df5ed5c..7a420d9 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,38 @@ -# Project Title + # Degan Gaming Project -Simple overview of use/purpose. +This repository is for the project assessment of the project of the 4th module of : solidity-avax-intermediate course of Metacrafters academy . The purpose of creating this to prove my learning and to showcase my skill as a solidity developer to the people. +# Problem Statement ## Description +Are you up for a challenge that will put your skills to the test? Degen Gaming 🎮, a renowned game studio, has approached you to create a unique token that can reward players and take their game to the next level. You have been tasked with creating a token that can be earned by players in their game and then exchanged for rewards in their in-game store. A smart step towards increasing player loyalty and retention 🧠 -An in-depth paragraph about your project and overview of use. +To support their ambitious plans, Degen Gaming has selected the Avalanche blockchain, a leading blockchain platform for web3 gaming projects, to create a fast and low-fee token. With these tokens, players can not only purchase items in the store, but also trade them with other players, providing endless possibilities for growth📈 -## Getting Started - -### Installing - -* How/where to download your program -* Any modifications needed to be made to files/folders - -### Executing program - -* How to run the program -* Step-by-step bullets -``` -code blocks for commands -``` +Are you ready to join forces with Degen Gaming and help turn their vision into a reality? The gaming world is counting on you to take it to the next level. Will you rise to the challenge 💪, or will it be game over ☠️ for you? -## Help +## Challenge +Your task is to create a ERC20 token and deploy it on the Avalanche network for Degen Gaming. The smart contract should have the following functionality: -Any advise for common problems or issues. -``` -command to run if program contains helper info -``` +Minting new tokens: The platform should be able to create new tokens and distribute them to players as rewards. Only the owner can mint tokens. +Transferring tokens: Players should be able to transfer their tokens to others. +Redeeming tokens: Players should be able to redeem their tokens for items in the in-game store. +Checking token balance: Players should be able to check their token balance at any time. +Burning tokens: Anyone should be able to burn tokens, that they own, that are no longer needed. +Solution Description +This program is a simple contract written in Solidity, a programming language used for developing smart contracts on the Ethereum blockchain. The contract has different functions that connnects our metacrafter wallet which is set on Avalnche fuji C-Chain testnet and can see all the transaction at: https://testnet.snowtrace.io and contract is deployed using Remix IDE: https://remix.ethereum.org/ with this smart contract all the above given are geing performed. -## Authors - -Contributors names and contact info - -ex. Dominique Pizzie -ex. [@DomPizzie](https://twitter.com/dompizzie) +It's essential to connect the metamask wallet with Avalanche Fuji C-Chain Testnet and to add view transaction to: https://testnet.snowtrace.io to check the transaction on the block viewer of Avalance Platform. +## Getting Started +## Executing Program +Open Remix IDE and create the Smart Contract named " DegenToken.sol " and paste the smart contract code to it. +Connect Metamask to the Remix IDE with the testnet account having AVAX token for the gas fee. +Deploy the contract using " Avalanche Fuji C-Chain " account. +Copy the Deployed contract address and go to https://testnet.snowtrace.io +Search the coppied address in the search box it will show all the transaction blocks of that smart contract. +Check All the functionality of my smart contract. +## Author +CodeBlocker52 ## License - -This project is licensed under the [NAME HERE] License - see the LICENSE.md file for details +This project is licensed under the MIT License - see the LICENSE file for details From 9630b48b2838f14acd4a9f1fc97c31c7f3f6e43d Mon Sep 17 00:00:00 2001 From: Kundan <131183962+CodeBlocker52@users.noreply.github.com> Date: Sun, 8 Oct 2023 15:16:52 +0530 Subject: [PATCH 4/4] Update DegenToken.sol --- contracts/DegenToken.sol | 93 ++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 23 deletions(-) diff --git a/contracts/DegenToken.sol b/contracts/DegenToken.sol index 9dad29a..23c786f 100644 --- a/contracts/DegenToken.sol +++ b/contracts/DegenToken.sol @@ -1,38 +1,85 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.18; +pragma solidity ^0.8.17; -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; +contract DegenToken{ + address public owner; + uint public totalSupply; + mapping (address => uint) public balanceOf; -contract DegenToken is ERC20, Ownable { + event Transfer(address indexed from, address indexed to, uint amount); - constructor() ERC20("Degen", "DGN") {} + struct Item { + uint itemId; + string itemName; + uint itemPrice; + } + + mapping(uint => Item) public items; + uint public itemCount; - // Mint new tokens. Only the owner can call this function. - function mint(address to, uint256 amount) public onlyOwner { - _mint(to, amount); + constructor() { + owner = msg.sender; + totalSupply = 0; } - // Transfer tokens to another address. - function transferTokens(address to, uint256 amount) public { - _transfer(msg.sender, to, amount); + modifier onlyOwner { + require(msg.sender == owner, "You are not the Owner so you cant't Mint the Tokens"); + _; } - // Redeem tokens for in-game items or rewards. - function redeemTokens(uint256 amount) public { - require(balanceOf(msg.sender) >= amount, "Insufficient balance"); - _burn(msg.sender, amount); - // Add logic here to provide in-game items or rewards. + string public constant name = "Degen Token"; + string public constant symbol = "DGN"; + + function transfer(address _address, uint _value) external returns (bool) { + require(balanceOf[msg.sender] >= _value, "You don't have enough Tokens to Transfer"); + + balanceOf[msg.sender] -= _value; + balanceOf[_address] += _value; + + emit Transfer(msg.sender, _address, _value); + return true; } - // Check the token balance of an address. - function checkTokenBalance(address account) public view returns (uint256) { - return balanceOf(account); + function mint(address _address,uint _value) external onlyOwner { + balanceOf[_address] += _value; + totalSupply += _value; + emit Transfer(address(0), _address, _value); } - // Burn tokens owned by the caller. - function burnTokens(uint256 amount) public { - require(balanceOf(msg.sender) >= amount, "Insufficient balance"); - _burn(msg.sender, amount); + function burn(uint _value) external { + require(_value > 0, "You have Zero Tokens on the platform"); + require(balanceOf[msg.sender] >= _value, "You have less number of token then what you want to burn"); + balanceOf[msg.sender] -= _value; + totalSupply -= _value; + + emit Transfer(msg.sender, address(0), _value); + } + + function addItem(string memory _itemName, uint256 _itemPrice) external onlyOwner { + itemCount++; + Item memory newItem = Item(itemCount, _itemName, _itemPrice); + items[itemCount] = newItem; + } + + function getItems() external view returns (Item[] memory) { + Item[] memory allItems = new Item[](itemCount); + + for (uint i = 1; i <= itemCount; i++) { + allItems[i - 1] = items[i]; + } + + return allItems; + } + + function redeem(uint _itemId) external { + require(_itemId > 0 && _itemId <= itemCount, "Enterd Wrong number of Item!!"); + Item memory redeemedItem = items[_itemId]; + + require(balanceOf[msg.sender] >= redeemedItem.itemPrice, "You can't Redeem this Item as you have less no of Tokens then the Required!!"); + + balanceOf[msg.sender] -= redeemedItem.itemPrice; + balanceOf[owner] += redeemedItem.itemPrice; + emit Transfer(msg.sender, address(0), redeemedItem.itemPrice); + } }