GithubHelp home page GithubHelp logo

lcsouzamenezes / simple-game-erc-721-token-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from idouble/simple-game-erc-721-token-template

0.0 0.0 0.0 105 KB

๐Ÿ”ฎ Very Simple ERC-721 Smart Contract Template to create your own ERC-721 Tokens on the Ethereum Blockchain, with many customizable Options ๐Ÿ”ฎ

License: MIT License

Solidity 100.00%

simple-game-erc-721-token-template's Introduction

๐Ÿ”ฎ Simple Game ERC-721 Token Template ๐Ÿ”ฎ

๐Ÿ”ฎ Very Simple ERC-721 Smart Contract Template to create your own ERC-721 Tokens on the Ethereum Blockchain, with many customizable Options ๐Ÿ”ฎ

๐Ÿ’Ž What is ERC-721? ๐Ÿ’Ž

ERC-721 is a free, open standard that describes how to build non-fungible or unique tokens on the Ethereum blockchain. While most tokens are fungible (every token is the same as every other token), ERC-721 Tokens are all unique.

One of the most known examples for an ERC-721 Token is Crypto Kitties (https://www.cryptokitties.co/), where each Cat is an unique ERC-721 Token. ๐Ÿ˜บ

โš™๏ธ Setup โš™๏ธ

Each Line of the Solidity Code has a comment that explains what is happening. ๐Ÿ“

The Setup is fairly easy, you just need to click on the Remix link or use the Gist link and you're done.
If you have problems with it, you can also do it the good old way and add each file separately. (Takes about 1 minute)

Remix IDE Link: https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=false&gist=6dfc6f9a27c0e6220094943657e3d834

GitHub Gist Link: https://gist.github.com/AYIDouble/6dfc6f9a27c0e6220094943657e3d834

Remix Solidity IDE Ethereum erc 721 erc721 erc-721 item game blockchain

Explanation of the Code:

At Line 5โ€“9: In the struct the Item with all his properties is defined (name, level, rarityLevel).

At Line 11: An Array is created, where all the Items of the contract owner are stored.

At Line 14โ€“16: We define that the owner is the user of the contract.

At Line 18: We define a function createItem, where the name (_name) of the Item is a parameter and the Ethereum address (_to) where we want to send our Items.

At Line 19: We define that only the owner of the contract is able to create Items.

At Line 20: Each time we create an Item the current Length of the Item array is being used as the ID for the Item. (Each Item has a unique ID)

At Line 21: The Item gets created and added to our Items array

At Line 22: The _mint function from the ERC721 Libraries is used for sending our Items to the specific ethereum address. As an example, this is needed to send the created Item to your ethereum address or any other address.

โš”๏ธ Item.sol โš”๏ธ (ERC-721 Token)

In this small example we are creating an ERC-721 Token, that could be used as an in-game Item. โš”๏ธ

Example: a Sword as a Item saved in the Ethereum Blockchain.

pragma solidity ^0.4.24;

contract Item is ERC721{
    
    struct Item{
        string name; // Name of the Item
        uint level; // Item Level
        uint rarityLevel;  // 1 = normal, 2 = rare, 3 = epic, 4 = legendary
    }
    
    Item[] public items; // First Item has Index 0
    address public owner;
    
    function Item() public {
        owner = msg.sender; // The Sender is the Owner; Ethereum Address of the Owner
    }
    
    function createItem(string _name, address _to) public{
        require(owner == msg.sender); // Only the Owner can create Items
        uint id = items.length; // Item ID = Length of the Array Items
        items.push(Item(_name,5,1)) // Item ("Sword",5,1)
        _mint(_to,id); // Assigns the Token to the Ethereum Address that is specified
    }
    
}

simple-game-erc-721-token-template's People

Contributors

idouble avatar imgbotapp avatar kirkins avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.