MetaMask - Invalid amount in MetaMask app on iPhone

strange, as it should to the same thing

So I guess there is problem with erc20, since its working with native matic.

Same issue on android metamask app. Works fine for native transfers. I also confirmed the raw transaction data matches.

Yes, I can send BNB on binance chain no problem, also MATIC on mumbai polygon chain, native works on desktop and mobile.

But erc20 works only on desktop. But I still dont know if this is metamask mobile problem or Moralis?

Having the exact same problem!
Did you manage to solve it somehow? Or understand why it happens ?

Nop, itā€™s not working. I though Moralis team would want to solve this problem, but there is no responseā€¦

did you try with ethers directly and it worked with an ERC20 token?

No, do you have example how to do it?

you can try something like this:

abi = [
{
        "constant": false,
        "inputs": [
            {
                "name": "_to",
                "type": "address"
            },
            {
                "name": "_value",
                "type": "uint256"
            }
        ],
        "name": "transfer",
        "outputs": [
            {
                "name": "",
                "type": "bool"
            }
        ],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    },
]

ethers = Moralis.web3Library
web3 = await Moralis.enableWeb3()
signer = web3.getSigner()
contract = new ethers.Contract("0xcontract_address", abi, web3)
await contract.connect(signer).transfer("0x321314124", 100)

I didnā€™t test it if it really works

Ok I tried this. Had to change value to ethers.utils.parseUnits(Amount, 18).

Result is, that this also worked only on desktop, but not on mobile app :confused:

it looks like a problem from metamask:

What is the best alternative to MetaMask?

usually wallet connect is used on mobile

Hi Guys,

Just add gasPrice in your transaction parameters and it will work.

RBE

1 Like

Please be kind and give me example how I set this, since there is nothing about that in moralis documentation. Thanks.

Hello RBE again. I tried this and I still get ā€œInvalid amountā€ error:

Try using ethers.js directly as youā€™ve tried before but with setting the gasPrice. You canā€™t set gasPrice in the options using Moralis, it wonā€™t use it.

Here is my last code:

This works on desktop and on mobile.

Maybe Moralis team should add option for gasLimit and gasPrice, otherwise you canā€™t user moralis for ERC20 transactionsā€¦

4 Likes

Hi there,
is there a fix for that ?
Having the exact same pb using unity.
Using the code from the documentation, on iphone and android:

public async void transferToken()
    {
        string EIPTransferTokenABI = "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]";
         // change the contract address to transfer different tokens
        string DAIContractAddress = "0x6B175474E89094C44Da98b954EedeAC495271d0F";
        string FunctioName = "transfer";
        string receiverAddress = "0x0EF9...";
        BigInteger DAIInWei = UnitConversion.Convert.ToWei(5, 18);
        // params - toAddress, amount
       object[] inputParams = { receiverAddress, DAIInWei };
        HexBigInteger value = new HexBigInteger("0x0");
        HexBigInteger gas = new HexBigInteger("800000");
        HexBigInteger gasprice = new HexBigInteger("230000");
        try
        {
            string result = await Moralis.ExecuteContractFunction(contractAddress: DAIContractAddress, abi: EIPTransferTokenABI, functionName: FunctioName, args: inputParams, value: value, gas: gas, gasPrice: gasprice);
            Debug.Log("Txhash :" + result);
        }
        catch (Exception error)
        {
            Debug.Log("Error :" + error);
        }
    }

Yes a solution is to set gas manually. Are you still getting the same ā€œInvalid amountā€ error? Try different gas values.