Writing the NFT marketplace smart contract
As usual, let’s create the Ape project by running these commands:
$ python3 -m venv .venv (.venv) $ pip install eth-ape'[recommended-plugins]'==0.7.23 (.venv) $ mkdir nft_marketplace (.venv) $ cd nft_marketplace (.venv) $ ape init Please enter project name: NFT Marketplace SUCCESS: NFT Marketplace is written in ape-config.yaml
Then create a smart contract file inside the contracts
folder named NFTMarketplace.vy
and add the following code to it:
#pragma version ^0.3.0 interface ERC721_Interface: def transferFrom(_from: address, _to: address, _tokenId: uint256): nonpayable def ownerOf(_tokenId: uint256) -> address: view
The pragma
line specifies that this smart contract can only be compiled using version 0.3.x of the Vyper compiler.
Then there are two ERC721 interfaces that you register in the smart contract because the NFT marketplace smart contract will interact...