git clone <marketplace nft project>
npm install
npx hardhat compile
npx hardhat ignition deploy ./ignition/modules/Marketplace.ts --network paseoAssetHub
- Polkadot Smart Contracts Documentation
- Polkadot Smart Contracts Tutorial
- Polkadot Smart Contract Basics
- Hardhat-Polkadot Plugin
- Paseo Blockscout
- Remix for Polkadot
- How to set up local revive node
Follow these instructions to get a local copy up and running for development and testing purposes.
-
Clone the repository:
git clone <Marketplace NFT on PolkaVM project>
-
Install dependencies:
npm install
-
Set up environment variables:
Create a file named
.env.local
in the root of your project and add your Pinata JWT for IPFS uploads. This is required for the minting functionality.NEXT_PUBLIC_PINATA_JWT=YOUR_PINATA_JWT_HERE
-
Run the development server:
npm run dev
Open http://localhost:3002 with your browser to see the result.
This section explains the key functionalities of the marketplace and how they are implemented.
The application uses RainbowKit to handle multi-wallet connections. In app/providers.tsx
, we configure the paseoAssetHub
chain to ensure that all web3 interactions are correctly routed to the PolkaVM testnet.
The components/sigpasskit.tsx
component is a wrapper around RainbowKit's ConnectButton
. It manages wallet connection and disconnection states, providing a seamless user experience for authentication and interaction with the blockchain.
To interact with the smart contract, the Application Binary Interface (ABI) and the contract's deployed address must be correctly configured.
- The Marketplace ABI is located in
lib/abi.ts
. - The contract address is stored in
lib/addresses.ts
.
Update these files if you deploy a new version of the smart contract.
This component is responsible for displaying all the NFTs currently listed for sale on the marketplace. It uses the useReadContract
hook from wagmi
to call the fetchMarketItems
function on the smart contract.
const { data: marketItems, isLoading: isLoadingMarketItems, refetch } = useReadContract({
address: NFT_MARKETPLACE_ADDRESS as Address,
abi: NFT_MARKETPLACE_ABI,
functionName: "fetchMarketItems",
args: [],
});
When a user wants to purchase an NFT, the application calls the buy
function in the smart contract. This is handled by the useWriteContract
hook from wagmi
, passing the tokenId
and the price
of the item.
await writeContractAsync({
address: NFT_MARKETPLACE_ADDRESS as Address,
abi: NFT_MARKETPLACE_ABI,
functionName: "buy",
args: [item.tokenId],
value: item.price,
});
This component displays the NFTs currently owned by the connected user. It calls the fetchMyNFTs
function on the smart contract to retrieve a list of NFTs associated with the user's address.
Users can create new NFTs through the application. This is a two-step process:
- The image and metadata are first uploaded to IPFS via the Pinata service.
- The returned IPFS URI is then passed to the
createToken
function in the smart contract to mint the new NFT and list it on the marketplace.
await writeContractAsync({
address: NFT_MARKETPLACE_ADDRESS as Address,
abi: NFT_MARKETPLACE_ABI,
functionName: "createToken",
args: [tokenURI, priceInWei],
value: listingPrice,
});
If a user owns an NFT that has been sold previously (or they simply want to relist it), they can put it back on the marketplace. This action calls the resellToken
function, requiring the tokenId
and a new price
.
await writeContractAsync({
address: NFT_MARKETPLACE_ADDRESS as Address,
abi: NFT_MARKETPLACE_ABI,
functionName: "resellToken",
args: [item.tokenId, priceInWei],
value: listingPrice,
});
Built with ❤️ by OpenGuild