Skip to content

Commit

Permalink
Add usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Electron committed Mar 11, 2024
1 parent 2cc336b commit 5df1669
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
3 changes: 1 addition & 2 deletions docs/build/isc/v1.0.0-rc.6/docs/how-tos/nft/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import DocCardList from '@theme/DocCardList';
# Native NFT and ERC721

The IOTA L1 has functionality to create NFTs, also called native NFTs. To use these NFTs on L2, you have
a ERC20 contract called `ERC721NFTs`. The following guides will show you how to [mint your own L1 NFT from L2](mint-nft.md), and [register](register-nft.md) it in the `ERC721NFTs` contract,
so it can be used like any other ERC721 NFT with some additional features.
a ERC20 contract called `ERC721NFTs` which contains all L1 NFTs owned by the chain. The following guides will show you how to [mint your own L1 NFT from L2](mint-nft.md), and [use](./use-as-erc721.md) it with the `ERC721NFTs` contract.

<DocCardList />
33 changes: 33 additions & 0 deletions docs/build/isc/v1.0.0-rc.6/docs/how-tos/nft/use-as-erc721.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
description: How to use a native NFT like an ERC721 NFT
image: /img/logo/WASP_logo_dark.png
tags:
- NFT
- EVM
- how-to
---

# Use as ERC721
## About the `ERC721NFTs` contract

The `ERC721NFTs` contract is a harcoded contract at address `0x1074030000000000000000000000000000000000`. Every <!-- TODO Confirm --> L1 NFT owned by the chain can be accessed through it. In this example we will show you how to use it by taking `transferFrom` as an example.

## Example Code

1. ERC721 uses `tokenID` for almost all interactions with it. So we first convert our `NFTID` to a `tokenID`:

```solidity
uint256 tokenID = uint256(NFTID.unwrap(nftID));
```

:::info Token ID to NFT ID

To go the other way around and convert a Token ID to an NFT ID, you can use the ISCTypes.asNFTID() function, by either using (`using ISCTypes for uint256;`) it on token ID like `tokenID.asNFTID();` or passing it to function like `ISCTypes.asNFTID(tokenID)`.

:::

2. Transfer the token with ID `tokenID`, by using the `ERC20NFTs` contract, which is exposed in the library as `ISC.nfts`, and calling the standard `transferFrom` function

```solidity
ISC.nfts.transferFrom(msg.sender, _destination, tokenID);
```

0 comments on commit 5df1669

Please sign in to comment.