# ERC721+ GSN + remote minting

**URL:** <https://forum.openzeppelin.com/t/erc721-gsn-remote-minting/1951>\
**Category:** Contracts\
**Tags:** erc721\
**Created:** [December 18, 2019, 10:59am UTC](https://forum.openzeppelin.com/t/erc721-gsn-remote-minting/1951 "2019-12-18T10:59:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![paolo.rollo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/paolo.rollo/32/2106_2.png) [@paolo.rollo](https://forum.openzeppelin.com/u/paolo.rollo)\
**Post date:** [December 18, 2019, 10:59am UTC](https://forum.openzeppelin.com/t/erc721-gsn-remote-minting/1951/1 "2019-12-18T10:59:38Z")

</div>

Hi everybody,

I’m new to the community, but I’m an old-time “OpenZeppelin user” 🙂

I would like to now if it’s possibile to pay for the gas of the minting operation of an ERC721 token by using the GSN in order to allow the contract creator to create new tokens without using Metamask et similia.

Don’t know really if this is the right section, feel free to close this topic or move if it is not compliant.

Thank you very much,  
PR

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [December 18, 2019, 11:15pm UTC](https://forum.openzeppelin.com/t/erc721-gsn-remote-minting/1951/2 "2019-12-18T23:15:36Z")

</div>

Hi @paolo.rollo,

Welcome to the community forum 👋

You can definitely `mint` via the GSN.

[GSN Strategies](https://docs.openzeppelin.com/contracts/2.x/gsn-strategies) covers the pre-built strategies and how to create your own custom strategy.

[Building a GSN powered (d)app from scratch](https://docs.openzeppelin.com/sdk/2.6/gsn-dapp) is great to start playing with a GSN dapp (this uses OpenZeppelin SDK and upgradeable contracts)

If you were creating an ERC721 token then you could do something similar to the following contract. Where `acceptRelayedCall` checks if the caller is a minter, and if it isn’t, rejects the call by returning `_rejectRelayedCall` with an error code, and if it is a minter accepts by returning `_approveRelayedCall`. That way only minters would have calls via the GSN approved.

If you have an existing ERC721 token, then you could create a minter contract that you give the minter role to, and only `acceptRelayedCall` from a white listed sender.

Please note, I haven’t tested the code below, so it would need appropriate testing and auditing.

```auto
pragma solidity ^0.5.5;

import "@openzeppelin/contracts/token/ERC721/ERC721Full.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721MetadataMintable.sol";

import "@openzeppelin/contracts/GSN/GSNRecipient.sol";

contract SimpleERC721 is ERC721Full, ERC721MetadataMintable, GSNRecipient {
    enum GSNRecipientSimpleERC721ErrorCodes {
        NOT_MINTER
    }

    constructor() ERC721Full("Token", "TKN") public {
    }

    function acceptRelayedCall(
        address relay,
        address from,
        bytes calldata encodedFunction,
        uint256 transactionFee,
        uint256 gasPrice,
        uint256 gasLimit,
        uint256 nonce,
        bytes calldata approvalData,
        uint256 maxPossibleCharge
    ) external view returns (uint256, bytes memory) {
        if (!isMinter(_msgSender())) {
            return _rejectRelayedCall(uint256(GSNRecipientSimpleERC721ErrorCodes.NOT_MINTER));
        }

        return _approveRelayedCall();
    }

    function _preRelayedCall(bytes memory context) internal returns (bytes32) {
    }

    function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal {
    }
}

```

---

<div class="post-metadata">

**Author:** ![paolo.rollo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/paolo.rollo/32/2106_2.png) [@paolo.rollo](https://forum.openzeppelin.com/u/paolo.rollo)\
**Post date:** [December 19, 2019, 10:41am UTC](https://forum.openzeppelin.com/t/erc721-gsn-remote-minting/1951/3 "2019-12-19T10:41:50Z")

</div>

Thank you very much for the fast reply @abcoathup!

Just another small question: is it possibile to pay the gas without using an ERC20 token? In other words, can it really be 100% free for the end user?

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [December 20, 2019, 1:15am UTC](https://forum.openzeppelin.com/t/erc721-gsn-remote-minting/1951/4 "2019-12-20T01:15:19Z")

</div>

Hi @paolo.rollo,

The [GSNRecipientERC20Fee](https://docs.openzeppelin.com/contracts/2.x/gsn-strategies#_gsnrecipienterc20fee) is a strategy that uses an ERC20 token, but you can use any strategy you need for your use case.

The sample ERC721 contract above just checks if the user requesting the relayed call is a minter, and if they are then any transactions on the contract are accepted via the GSN for them. Which means that the minter isn’t paying for gas, doesn’t need an ERC20 token, it is 100% free for the minter.

As an example you can have a look at the demo GSN Chat App which is 100% free for the end user: [https://gsn-chat-app.openzeppelin.com/](https://gsn-chat-app.openzeppelin.com/)

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [December 23, 2019, 12:32am UTC](https://forum.openzeppelin.com/t/erc721-gsn-remote-minting/1951/5 "2019-12-23T00:32:56Z")

</div>

Hi @paolo.rollo,

Feel free to ask all the questions that you need.

If you have a moment it would be great to [introduce yourself](https://forum.openzeppelin.com/t/introduce-yourself-here/88) or share [what you are working on](https://forum.openzeppelin.com/t/what-are-you-working-on/744) with the community.
