/nft-token

buying and selling NFTs with custom ERC20 Token (hardhat, remix)

Primary LanguageJavaScript

nft-custom-erc20-buy


If using the latest commit, please follow these steps to deploy and test in remix/testnet.

Deploy the SolToken contract first, providing an initial supply of, say 1 million :

1000000000000000000000000


Deploy the NFTMarket contract by providing the address of SolToken, which we just deployed :

$ SolToken Address


Deploy the NFT contract by providing the address of NFTMarket, which we just deployed :

$ NFTMarket Address


Now, in NFT, using seller's account, Invoke createToken method with, say "token1uri" :

"token1uri"

This will store this URI against tokenId "1".

Now, in NFTMarket, using seller's account, Invoke createMarketItem method with following args {NFTAddress, tokenId(1), price(say 50 SOL)} :

$ NFT Address
1
50000000000000000000

Note: In msg.value, give 0.025 ether as listingFee

25000000000000000

This will list our item in NFT Market Place against itemId "1".

Now, in SolToken, using buyer's account, Invoke approve with following args {NFTMarketAddress, amount(50 SOL)} :

$ NFTMarket Address
50000000000000000000

This will approve NFTMarket to transfer tokens from buyer to itself.

Now, in NFTMarket, using buyer's account, Invoke createMarketSale method with following args {NFTAddress, itemId(1)} :

$ NFTMarket Address
1

This will transfer the itemId "1" NFT to buyer and transfer 50 SOL to seller. Also, it will transfer 0.025 ether listingFee from NFTMarket to the owner of contract.



To test locally with hardhat, pull the previous commit and :
npx hardhat compile
npx hardhat test