How to set NFT prices using a custom token in my game?

I’m working on an NFT game and want players to buy NFTs with my own token. Think of how Decentraland uses MANA for their NFTs.

I’ve got the basics down - I can create both tokens and NFTs. Here is a fresh version of my token contract code:

pragma solidity ^0.8.2;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract GameCoin is ERC20 {
    constructor() ERC20('GameCoin', 'GC') {
        _mint(msg.sender, 1000000 * (10 ** decimals()));
    }
}

I’m stuck figuring out how to assign prices to my NFTs using this token. I checked OpenSea but their custom token option seems outdated and doesn’t work anymore.

Can anyone help me figure out how to integrate my token as a pricing method in the NFT marketplace? Thanks a lot!

To set NFT prices using your custom token, you’ll need to create a dedicated marketplace contract. This contract will act as an intermediary, handling the buying and selling logic while interfacing with both your NFT and token contracts.

In your marketplace contract, implement functions for listing NFTs, setting prices in your GameCoin, and executing purchases. You’ll need to include approval mechanisms to allow the contract to transfer tokens and NFTs on behalf of users.

Consider implementing a price feed or oracle system to handle any necessary conversions between your token and other currencies. This can help maintain price stability and provide more flexibility for users.

Remember to thoroughly test your smart contracts and consider getting a professional audit before deployment to ensure security and proper functionality. Good luck with your NFT game project!

yo ray84, cool idea! i’ve done smthing similar. u need a custom marketplace contract to handle buyin/sellin with ur token. it’ll interact with both ur NFT and token contracts. make sure to include approval funcs so peeps can spend tokens. gl with ur project, sounds dope!

hey there Ray84! that’s a pretty cool project you’ve got going on :sunglasses: i’m also working on somethin similar and ran into the same issue. have you looked into using a custom marketplace contract? that might be the way to go

i found this awesome tutorial on youtube that shows how to make a marketplace that uses your own token for pricing. it’s a bit long but super helpful. basically you create a separate contract that handles all the buying/selling logic and references your token contract for payments

one thing to watch out for - make sure you handle approvals properly so users can spend their tokens on nfts. also double check the math for any price conversions to avoid funky rounding errors

what kind of nfts are you planning for your game? sounds intriguing! let me know if you want to bounce ideas around sometime