I'm trying to figure out how to mint my own NFT (erc721) with my own erc20 token. All the references online give me info on how to deploy to other networks ie polygon, arbitrum etc. That's not exactly what I'm looking for.

currently the code for price is set in ether

uint256 public constant MINT_PRICE = .069420 ether;

I would like to have it set in my own erc20 token if possible.


2 Answers 2


Rememeber you will need to approve the token transfer before calling the mint functions, but it should look like this:

//Imports ERC721 and ERC20
contract Example is ERC721{

    uint256 public constant MINT_PRICE = .069420 ether;
    ERC20 public MyToken;

    constructor(address token) public {
       MyToken = ERC20(token);

    function _mint(address to, uint256 tokenId) internal virtual override{
        require(MyToken.allowance(masg.sender, address(this)) == MINT_PRICE, "Not enough of my token");//To ensure they will deposit the right amount
        MyToken.transferFrom(msg.sender, address(this), MINT_PRICE);

        super._mint(to, tokenId);

This is actually very easy process. To mint the NFT using your own ERC20 token you have to use your token interface instance inside the NFT contract as shown in the code by @Julissa above.

Before that you have to approve the ERC20 token using web3 in front end to the NFT contract so that your NFT contract can use transferFrom method to use the ERC20 token from your wallet address.

You might have used defi like uniswap before, to sell your token (eg USDT) in uniswap, you first have to approve the token to spend to uniswap router address.

The approve and transferFrom methods are very important for DEFI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.