-
I am trying to call a function named The // Get the accounts
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
// Connect to JSONRPC provider
const provider = await new ethers.providers.JsonRpcProvider("https://polygon-rpc.com");
// Get the signer from the provider with address from MetaMask
const signer = newProvider.getSigner(accounts[0]);
// Create new contract with contract address, abi and signer
const contract = new ethers.Contract(process.env.NEXT_PUBLIC_CONTRACT_ADDRESS!, ABI, signer);
// Call the mint function from the smart contract with 1 as parameter.
// The payable amount should be 0 as I only want to pay for gas.
const result = await contract.mint(BigNumber.from('1'), { value: BigNumber.from('0') }); This returns the error below:
The body is just {"jsonrpc":"2.0","id":60,"error":{"code":-32000,"message":"unknown account"}} I know that the function is indeed being called, because when I try from another address that is not the owner of the contract, then I get an error saying that the address is not whitelisted (a requirement I implemented in the smart contract) as it is supposed to. Does anyone know why I get this "Unknwon account" error? Is it related to the signer and JSONRPC? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'm not sure where Let me know if that works. :) |
Beta Was this translation helpful? Give feedback.
I'm not sure where
newProvider
is coming from, but you need to get the Signer from the provider that controls the Signer; you likely wantnewProvider = new ethers.providers.Web3Provider(window.ethereum)
to get the Signer from.Let me know if that works. :)