Game that uses its own currency + NFTs

Hello everyone.

I am finalizing plans for a game that makes extensive usage of different sorts of NFTs. There is a point system planned, and the idea is to have these points purchased using an ERC20 token, that would be tradable on a DEX.

My question is in relation to this ERC20 token in fact:
since I plan to build this NFT system using an ERC5511 token that has the definitions of all my NFTs, will I need to create the ERC20 token separately and hard code its contract address in the game, or can I have the ERC20 created as well within the same ERC5511 contract?

I am sure I am missing something here, and so I thank you for your kindness and assistance.

1 Like

(not an expert but) My understanding is that you need to create the ERC20 token as a seperate contract and deploy that first.

Then import the ERC20 interface into your ERC5511 and reference the ERC20 token contract address into a local variable that you can then use.

We do something similar with our DEX contract that uses an ERC20 within it for transactions.

e.g.

import "@openzeppelin/[email protected]/token/ERC20/ERC20.sol";

contract myNewContract {
    ERC20 public myToken;

   // on contract deployment, send in the ERC20 deployed address
    constructor(ERC20 _myERC20TokenAddress) {
        myToken = _myERC20TokenAddress;
    }

  // now you can call any ERC20 methods on myToken
}


Hope that helps

2 Likes

thank you for your response.

I am fairly new to solidity, but intuitively that’s what I was thinking as well.

1 Like

Each item in an ERC1155 collection is kinda like an ERC20 token in that they are fungible… however a DEX can only use ERC20 tokens. Could still have the points as an ERC1155 item, but it would need to be wrapped in an ERC20 token anyway to be traded on a regular DEX like Uniswap- otherwise it would need to be listed on an NFT marketplace like Opensea.

And yes, you’d need to have the ERC20 address in your dapp (and the ABI) in order to interact with it. Can have the contract address and ABI in a settings file that you import to keep it from being hard coded.

1 Like