Skip to content

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

License

Notifications You must be signed in to change notification settings

IDouble/Simple-Game-ERC-721-Token-Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

40 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ”ฎ 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
    }
    
}

Binance Ready to give crypto a try ? buy bitcoin and other cryptocurrencies on binance