Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final code #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 27 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
85 changes: 78 additions & 7 deletions contracts/DegenToken.sol
Original file line number Diff line number Diff line change
@@ -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);

}
}