ERC721SmartToken — ERC721 Token with ERC20 Adapter

Sergei Sevriugin
Coinmonks
2 min readApr 1, 2018

--

Image result for erc721
source

ERC721SmartToken contract implements non-fungible tokens based on ERC721 standard that also supports ERC20interface. The main idea is to create a token that can be both non-fungible and has transferable value.

Inside ERC721 contract each not fungible token represented as a NFT structure where there is a member element called value.

This element holds ERC20 token inside ERC721 token.

To work with ERC721 token as normal ERC20 token we need to create a ERC20Adapter that implements standard ERC20 methods, as for example balanceOf method.

But in our case due to ERC721 structure for each _owner there can be many non-fungible tokens belong to this particular address. To select particular token for ERC20 compatible operations like transfer token value to another address we need to implement new methods that will accept address and token ID as parameters.

This method calls ERC20Controller method implemented by ERC721SmartToken contract that will use the following mappings to store information abount NFT tokens:

Now we can use ERC20 standard methods transfer and transferFrom to transfer values between two NFT tokens.

ERC20Controller implements defaultId methods that provides a default NFT id for the _owner address.

So, we can use ERC20 standard method approve to approve transfer between two NFT default tokens for msg.senderand _spender.

REGA Risk Sharing GitHub

Get Best Software Deals Directly In Your Inbox

--

--