Hi @paolo.rollo,
Welcome to the community forum
You can definitely mint
via the GSN.
GSN Strategies covers the pre-built strategies and how to create your own custom strategy.
Building a GSN powered (d)app from scratch 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.
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 {
}
}