Smilo-platform / erc721

Simple ERC721 Token Example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A Simple ERC-721 on Smilo network Example

What is it?

ERC-721 tokens are a hot topic today with the advent of crypto kitties and a host of other digital collectibles spawned by its success. The ERC-721 standard has gone through a couple iterations and is more or less in place now, so expect more and more players to enter this space. The basic premise of these non-fungible tokens is that each token is unique and therefore cannot be exchanged on a 1:1 basis like an ERC20 token may be. There are many use cases where a unique tangible or digital asset may represented by these ERC-721 tokens, such as real estate, art, precious stones, etc. Actually, the digital collectible use case is probably the lowest market value use case of them all.

Purpose of this article

This article will attempt to create an ERC-721 in its simplest useful form using the OpenZeppelin implementation of the ERC-21 standard. I would recommend looking at the standard linked above in order to familiarize yourself with the requirements as they can be sometimes be hidden in the excellent OpenZeppelin implementations. There is also a fantastic article written here that describes in-depth the ERC-721 spec.

Setup the project

  1. yarn

The Token

Deploy yourself: truffle migrate --network testnet

Testnet: 0xE4c1A5C3CF5bAB951DED3aaebF79241D67d6e91A

Explorer: https://testnet-explorer.smilo.network/addr/0xe4c1a5c3cf5bab951ded3aaebf79241d67d6e91a

Mainnet:

Test it out

Run the test from the project root

truffle test

Addendum

Pretty much all of the regular ERC20 functions are available in the ERC721 contracts. You can approve a third party to spend your token, burn tokens, etc. The functionality is the same, but the inputs and what happens under the covers is a bit more complex. There are a couple ERC721 methods that are not discussed in this article that are worth independent study as well

  • safeTransferFrom

  • isApprovedForAll

  • setApprovedForAll

Summary

Let’s recap what we learned in this article. First, we setup the project with truffle and imported our dependencies including the world class smart contract library, **OpenZeppelin. **Next, we coded our ERC721 token using the OpenZeppelin — *ERC721Token *template. We ran through a few checks to make sure our contract was valid and then we setup a mocha test to test our assertions. Our solidity code is deceptively simple and I would recommend a deeper dive into the ERC721 standard and the OpenZeppelin implementation. We accomplished our purpose in this article by creating a simple ERC721 token and you should be in a good place to continue your journey in learning this new token type. Even though this token was not ‘fungeable’ — I hope you still had ‘fun’ :)

About

Simple ERC721 Token Example


Languages

Language:JavaScript 100.0%