Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ]

Here is my code:

const sendOptions = {
chain: “bsc testnet”,
contractAddress: ERC721BSCMockAddress,
functionName: “mint”,
abi: ERC721BSCMintABI,
params: {
tokenId: nftBody.tokenId,
to: nftBody.toAddress
},
};

const transaction = await Moralis.executeFunction(sendOptions);
const receipt = await transaction.wait();

I have given right params and it is working on remix.ethereum.org but it is not working with moralis. I have read some answers too but can’t help myself. Please help me.

This error may occur in the following instances
-If you are calling the smart contract function on the wrong chain
-If the function is not allowed to call from different wallets addresses

Sorry to say. But I have tried with the right chain and the right wallet. But still it is not working.

Can you please suggest me a way?

Can you share the contract address, ABI, and chain details to test.
and function code if available.

Yes, sure.
Contract address: 0xD09c517b2b59A9bf1429a7e87d8c7CaA554Ac130
Find it from: https://testnet.bscscan.com/address/0xD09c517b2b59A9bf1429a7e87d8c7CaA554Ac130
ABI: [
{
“inputs”: [
{
“internalType”: “string”,
“name”: “name_”,
“type”: “string”
},
{
“internalType”: “string”,
“name”: “symbol_”,
“type”: “string”
}
],
“stateMutability”: “nonpayable”,
“type”: “constructor”
},
{
“anonymous”: false,
“inputs”: [
{
“indexed”: true,
“internalType”: “address”,
“name”: “owner”,
“type”: “address”
},
{
“indexed”: true,
“internalType”: “address”,
“name”: “approved”,
“type”: “address”
},
{
“indexed”: true,
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
}
],
“name”: “Approval”,
“type”: “event”
},
{
“anonymous”: false,
“inputs”: [
{
“indexed”: true,
“internalType”: “address”,
“name”: “owner”,
“type”: “address”
},
{
“indexed”: true,
“internalType”: “address”,
“name”: “operator”,
“type”: “address”
},
{
“indexed”: false,
“internalType”: “bool”,
“name”: “approved”,
“type”: “bool”
}
],
“name”: “ApprovalForAll”,
“type”: “event”
},
{
“anonymous”: false,
“inputs”: [
{
“indexed”: true,
“internalType”: “address”,
“name”: “from”,
“type”: “address”
},
{
“indexed”: true,
“internalType”: “address”,
“name”: “to”,
“type”: “address”
},
{
“indexed”: true,
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
}
],
“name”: “Transfer”,
“type”: “event”
},
{
“inputs”: [
{
“internalType”: “address”,
“name”: “to”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
}
],
“name”: “approve”,
“outputs”: [],
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “address”,
“name”: “owner”,
“type”: “address”
}
],
“name”: “balanceOf”,
“outputs”: [
{
“internalType”: “uint256”,
“name”: “”,
“type”: “uint256”
}
],
“stateMutability”: “view”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
}
],
“name”: “getApproved”,
“outputs”: [
{
“internalType”: “address”,
“name”: “”,
“type”: “address”
}
],
“stateMutability”: “view”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “address”,
“name”: “owner”,
“type”: “address”
},
{
“internalType”: “address”,
“name”: “operator”,
“type”: “address”
}
],
“name”: “isApprovedForAll”,
“outputs”: [
{
“internalType”: “bool”,
“name”: “”,
“type”: “bool”
}
],
“stateMutability”: “view”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “address”,
“name”: “to”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
}
],
“name”: “mint”,
“outputs”: [],
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“inputs”: [],
“name”: “name”,
“outputs”: [
{
“internalType”: “string”,
“name”: “”,
“type”: “string”
}
],
“stateMutability”: “view”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
}
],
“name”: “ownerOf”,
“outputs”: [
{
“internalType”: “address”,
“name”: “”,
“type”: “address”
}
],
“stateMutability”: “view”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “address”,
“name”: “from”,
“type”: “address”
},
{
“internalType”: “address”,
“name”: “to”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
}
],
“name”: “safeTransferFrom”,
“outputs”: [],
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “address”,
“name”: “from”,
“type”: “address”
},
{
“internalType”: “address”,
“name”: “to”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
},
{
“internalType”: “bytes”,
“name”: “_data”,
“type”: “bytes”
}
],
“name”: “safeTransferFrom”,
“outputs”: [],
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “address”,
“name”: “operator”,
“type”: “address”
},
{
“internalType”: “bool”,
“name”: “approved”,
“type”: “bool”
}
],
“name”: “setApprovalForAll”,
“outputs”: [],
“stateMutability”: “nonpayable”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “bytes4”,
“name”: “interfaceId”,
“type”: “bytes4”
}
],
“name”: “supportsInterface”,
“outputs”: [
{
“internalType”: “bool”,
“name”: “”,
“type”: “bool”
}
],
“stateMutability”: “view”,
“type”: “function”
},
{
“inputs”: [],
“name”: “symbol”,
“outputs”: [
{
“internalType”: “string”,
“name”: “”,
“type”: “string”
}
],
“stateMutability”: “view”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
}
],
“name”: “tokenURI”,
“outputs”: [
{
“internalType”: “string”,
“name”: “”,
“type”: “string”
}
],
“stateMutability”: “view”,
“type”: “function”
},
{
“inputs”: [
{
“internalType”: “address”,
“name”: “from”,
“type”: “address”
},
{
“internalType”: “address”,
“name”: “to”,
“type”: “address”
},
{
“internalType”: “uint256”,
“name”: “tokenId”,
“type”: “uint256”
}
],
“name”: “transferFrom”,
“outputs”: [],
“stateMutability”: “nonpayable”,
“type”: “function”
}
];

Contract: https://github.com/avolabs-io/nft-auction/blob/master/contracts/ERC721MockContract.sol (mint function)

I am able to mint. I minted a token with id: 123

Chain is not required in the options. I guess removing this might solve the issue.

These are the function parameters I used.

abi= {
"inputs": [
{
"internalType": "address",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "mint",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
};

const options = {
  contractAddress: "0xD09c517b2b59A9bf1429a7e87d8c7CaA554Ac130",
  functionName: "mint",
  abi: [abi],
  params: {
      to: "0x5C1584E75Ac66347Be35A1cc824Ead2aF4b50c85",
      tokenId: "123",
  }
};
const transaction = await Moralis.executeFunction(options);
const result = await transaction.wait();

Still I am getting the same error with this code. I am really afraid about it. :sob:

Can you please provide me the code how your have connected with the SDK using private key?

If you have multiple wallets in metamask, try disconnecting the other wallet addresses and make sure only the loggedin wallet is connected.

I did not use a private key to connect.
I just used Moralis.authenticate() to connect to wallet and Moralis.executeFunction to run the contract function.

Sorry to say. This line may look odd. I am working with the backend only and with no frontend. Just sending this request using API and using a private key and wallet address.

I haven’t tried executefunction from the server-side.

See if this doc helps:
https://docs.moralis.io/moralis-dapp/connect-the-sdk/connect-using-node#moralis.executefunction

Try setting a high manual gas limit to see if you can get past the error. To do this you will have to use ethers.js directly.

Here is an example.

Thank a lot. Error is solved.