Hi. I have a minting Dapp on BSC Testnet that pops the user to mint an NFT when a button is clicked. It works fine with MetaMask as an extension for Chrome in Desktop, but for the MetaMask built-in browser in the Android app, the majority of times (although sometimes not, which is weird), the āConfirmā button is grayed out and the user canāt confirm the transaction (of course I checked the address has more than enough balance for both the minting price and the fees).
The thing that I noticed is that, in Desktop, the MetaMask extension correctly reads the āFunction typeā, showing the name of the function in the smart contract, which I called mintNFT
. In mobile, however, it always shows Unknown Method
, even the few times that the āConfirmā button is enabled (with the transaction working just fine).
Hereās the React code that runs onClick
on the button:
onClick={userAddress ?
async () => {
try {
setMintPending(true)
const allowance = await Moralis.executeFunction({
abi: mintNFTABI,
chain: chain,
contractAddress: contractAddress,
functionName: "mintNFT",
params: {
numberOfTokens: numberToMint
},
msgValue: Moralis.Units.ETH(numberToMint * mintingPrice)
})
setMintPending(false)
} catch (e) {
setMintPending(false)
console.log("Transaction cancelled by user.")
}
}
-
userAddress
andnumberToMint
are state variables, with the user address and the number of NFTs to mint in the transaction, respectively, -
setMintPending
sets another state variable that itās used to simply change the button text from āMintā to āPendingā, -
mintingPrice
is a constant defining the price of 1 NFT (when the āconfirm transactionā window is shown on MetaMask,numberToMint * mintingPrice
is always shown correctly).
Thanks for your time!