I have a method as the following, and the intent of this method is that I would like it to check if a user has authorised my smart contract to withdraw his USDC from the polygon USDC contract.
When I execute this method in JS, I get the following error in Metamask (console)
inpage.js:1 MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: 'Internal JSON-RPC error.', data: {…}} code: -32603 data: {code: -32000, message: 'out of gas'} message: "Internal JSON-RPC error." [[Prototype]]: Object
The address I'm executing this has sufficient Matic to pay for the gas of this transaction.
I'm somewhat stumped as to why this is failing and not executing.
Any ideas ? (PS: I put address1 and address2 for confidentiality reasons as dont want to be posting my public address)
async function checkallowance() {
let fUSDC = "0x2791bca1f2de4661ed88a30c99a7a9449aa84174"
let contractABI = [{"name":"Transfer","inputs":[{"type":"address","name":"sender","indexed":true},{"type":"address","name":"receiver","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false,"type":"event"},{"name":"Approval","inputs":[{"type":"address","name":"owner","indexed":true},{"type":"address","name":"spender","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false,"type":"event"},{"name":"FX","inputs":[{"type":"address","name":"_from","indexed":true},{"type":"uint256","name":"_amount","indexed":false},{"type":"string","name":"_targetfx","indexed":false}],"anonymous":false,"type":"event"},{"outputs":[],"inputs":[{"type":"string","name":"_name"},{"type":"string","name":"_symbol"},{"type":"uint256","name":"_decimals"},{"type":"uint256","name":"_supply"}],"stateMutability":"nonpayable","type":"constructor"},{"name":"transfer","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"_to"},{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function","gas":74683},{"name":"transferFrom","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"_from"},{"type":"address","name":"_to"},{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function","gas":111038},{"name":"approve","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"_spender"},{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function","gas":37764},{"name":"mint","outputs":[],"inputs":[{"type":"address","name":"_to"},{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function","gas":75614},{"name":"fx","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"uint256","name":"_amount"},{"type":"string","name":"_targetfx"}],"stateMutability":"nonpayable","type":"function","gas":83253},{"name":"name","outputs":[{"type":"string","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":7643},{"name":"symbol","outputs":[{"type":"string","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":6696},{"name":"decimals","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1301},{"name":"balanceOf","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":1546},{"name":"allowance","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"},{"type":"address","name":"arg1"}],"stateMutability":"view","type":"function","gas":1791},{"name":"totalSupply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1391}]
const provider = new ethers.providers.Web3Provider(window.ethereum);
var [account] = await ethereum.request({
method: 'eth_requestAccounts'
});
const signer = provider.getSigner(account);
const contract = new ethers.Contract(
fUSDC,
contractABI,
signer
);
let checkAllowance = await contract.allowance(address1,address2)
let formattedAllowance = checkAllowance.toString();
await console.log(formattedAllowance);
}