Challenge #0: 🖼️ Simple NFT Example | Speedrun Ethereum With Vyper 🐍
Tags: blockchain, web3, vyper, python
Published: 2023-02-15 15:56:05

## Table of contents
 * [🎟 Introduction](#chapter-1)
 * [📦 Setup](#setup)
 * [📑 Code](#code)
 * [🔬 Conclusion](#conclusion)

## 🎟 Introduction <a name="introduction"></a>
The ERC-721 token standard serves as the foundation for Non-Fungible Tokens (NFTs), providing developers with the capability to design unique digital assets that cannot be duplicated on a blockchain. This feature unlocks the potential for an entirely new realm of experiences, including exclusive access to gated websites or communities restricted to select token holders, as well as innovative games where each item possesses distinct properties such as resealability, multi-functionality, and complete ownership.

In the initial segment of this challenge, we will explore the process of implementing an NFT through the utilization of the Vyper programming language.

The ability to create and exchange unique digital assets through NFTs has opened up new opportunities for content creators, artists, and collectors to monetize and showcase their work in innovative ways. NFTs have enabled the creation of digital art, music, and collectibles that can be traded bought, and sold as one-of-a-kind assets while providing a secure and transparent record of ownership on the blockchain.

Furthermore, the utilization of Vyper programming language in implementing NFTs offers a number of advantages, including higher security, improved gas efficiency, and enhanced readability of the code, which in turn increases the ease of development and maintenance of NFT projects.

## 📦 Setup <a name="setup"></a>
For setting up the project on a local machine, only one essential component is required: 

- [Python](https://www.python.org/)

[Python](https://www.python.org/) is the primary programming language used in the project, it includes [PIP](https://pypi.org/project/pip/), which serves as the package manager for Python and [Virtual ENV](https://docs.python.org/3/library/venv.html) is an essential tool used for creating a virtual environment that will house the application's code.

While the process for setting up these components is beyond the scope of this challenge, in essence, it involves installing Python and configuring a virtual environment for the application's code. It is important to note that creating a virtual environment for the project ensures that the application's dependencies and requirements are isolated from those of the host system, thereby improving stability and reproducibility.


### Brownie
If you are going to use [Brownie](https://eth-brownie.readthedocs.io) in this challenge, in your `virtual environment`, [go ahead and install Brownie, after you installed it](https://eth-brownie.readthedocs.io/en/stable/install.html), create a new folder called `nft` and inside it run the following command:

```bash
$ brownie init
```

Also, you might want to use the Hardhat node to test our smart contracts, so inside your project folder, run the following command:

```bash
$ npm install --save-dev hardhat
```

### ApeWorx
If you are going to use [ApeWorx](https://docs.apeworx.io/ape/stable/userguides/quickstart.html#documentation) in this challenge, activate your `virtual environment` and install ApeWorx:

```bash
$ pip install eth-ape'[recommended-plugins]'
```

After you installed it, create a new folder called `nft` and inside it run the following command:

```bash
$ ape init
```

## 📑 Code <a name="code"></a>
The ERC-721 token standard serves as the foundation for Non-Fungible Tokens (NFTs). Inside your `contracts` folder, create a file called `nft.vy` this will contain all of the code necessary to implement the ERC-721.

### Non-Fungible Token (ERC-721)
Here is a barebones implementation of the `ERC721` token standard in Vyper, can you turn it into a working smart contract?

> **Important**: ⚠️🐍 If you are new to Vyper, don't worry, it was designed to be simple and readable, making it easier for programmers with any level of experience to quickly grasp the language. If you need more guidance, there are many resources available online to help you get started, such as the Vyper [documentation](https://docs.vyperlang.org/en/stable/vyper-by-example.html), [tutorials](https://vyper-by-example.org/), and community forums.

```python
# @version >=0.3.7
from vyper.interfaces import ERC165
from vyper.interfaces import ERC721

### INTERFACES ###
implements: ERC721
implements: ERC165

### EVENTS ###
event Transfer:
    sender: indexed(address)
    receiver: indexed(address)
    tokenId: indexed(uint256)

event Approval:
    owner: indexed(address)
    approved: indexed(address)
    tokenId: indexed(uint256)

event ApprovalForAll:
    owner: indexed(address)
    operator: indexed(address)
    approved: bool


### METHODS ###
@external
@view
def balanceOf(_owner: address) -> uint256:
    # ... TODO: Implementation
    return 0


@external
@view
def ownerOf(_tokenId: uint256) -> address:
    # ... TODO: Implementation
    return empty(address)


@external
def safeTransferFrom(_from: address, _to: address, _tokenId: uint256, _data: Bytes[1024]=b"")
    # ... TODO: Implementation
    pass


@external
def transferFrom(_from: address, _to: address, _tokenId: uint256):
    # ... TODO: Implementation
    pass


@external
def approve(_to: address, _tokenId: uint256):
    # ... TODO: Implementation
    pass


@external
def setApprovalForAll(_operator: address, _approved: bool):
    # ... TODO: Implementation
    pass


@external
@view
def getApproved(_tokenId: uint256) -> address:
    # ... TODO: Implementation
    return empty(address)


@external
def isApprovedForAll(_owner: address, _operator: address) -> bool:
    # ... TODO: Implementation
    return false
```

> Feel stuck? Take a look at the [Vyperlang Official Implemenation](https://github.com/vyperlang/vyper/blob/master/examples/tokens/ERC721.vy)

## 🔬 Conclusion <a name="conclusion"></a>

In this challenge, we explored the process of implementing an NFT using the Vyper programming language, which provides developers with a secure and gas-efficient approach to creating unique digital assets that cannot be duplicated on a blockchain. We provided a barebones implementation of the ERC-721 token standard in Vyper and challenged readers to turn it into a working smart contract by implementing the necessary methods and events.

Creating and exchanging unique digital assets through NFTs has opened up new opportunities for content creators, artists, and collectors to monetize and showcase their work in innovative ways. NFTs have enabled the creation of digital art, music, and collectibles that can be traded bought, and sold as one-of-a-kind assets while providing a secure and transparent record of ownership on the blockchain.

> 📒 **Note**: Whether using [Brownie](https://eth-brownie.readthedocs.io/en/stable/) or [ApeWorx](https://www.apeworx.io/), creating a virtual environment for the project ensures that the application's dependencies and requirements are isolated from those of the host system, improving stability and reproducibility.

<br>

> 🐍 **Note**: The [Vyper programming language](https://vyper.readthedocs.io/) offers a number of advantages over other languages, including higher security, improved gas efficiency, and enhanced code readability, making it a great option for NFT development projects.