0

made a simple contract that mints 721 token to an address

contract mint is ERC721URIStorage, BaseRelayRecipient {
string private greeting;
uint256 tokenId;

constructor() ERC721("GameItem", "ITM") {
    tokenId = 1;
}

function getTokenId() public view returns (uint256) {
    return tokenId;
}

function mintToken() public returns (uint256) {
    _mint(_msgSender(), tokenId);
    tokenId += 1;
    return tokenId;
}

this is what the code looks like but whenever I call the mintToken() function from client-side, instead of minting it to my address that token in minted to the relayers address who made the call on my behalf, is there something that I'm doing wrong?

Also when I call the mintToken() function from the client-side, metamask doesn't popup for me to sign the transaction, instead it just happens and then the token in minted to the relayers contract instead of mine.

Is there something that I doing wrong on the client side?

Is there any way to mint token (gas-less) using biconomy?

1 Answer 1

1

You shouldn't use _msgSender() when working with Biconomy because they call the contract for you and their address would always be the msg.sender so you have to structure the function so that it receives a signature and then gets the minter address from the signature.

Example using EIP712 Standard:

function mint(Sig memory _sig, address _minter) external  {
        // Perform EIP712 hashing for address retrieval
        bytes32 digest = keccak256(
            abi.encodePacked(
                "\x19\x01",
                _domainSeparatorV4(),
                keccak256(
                    abi.encode(
                        _META_TRANSACTION_SIGNATURE_TYPE_HASH,
                        _minter
                    )
                )
            )
        );

        address recoveredAddress = ecrecover(digest, _sig.v, _sig.r, _sig.s);
}

So, you will get the signature from the user on the client-side and then pass it into the function.

You could also use another method to get the signature but basically don't use _msgSender() to perform the operation.

1
  • Hey, thanks for your answer, I get it now. So what if there's a user-specific function like _transfer() that transfers the NFT only if it is called by the owner of that token? Is it possible to do the same using the above method?
    – Atul Patil
    Jul 13, 2022 at 9:16

Your Answer

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

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