0

I'm trying to call a function of my contract deployed on testnet mumbai but I can't get it working. Here's the code

const ethers = require('ethers');
const addressOfContract = "0x09C7CC4593C4Fe030bf1704051fa9ED889A30cC7";
const baseURI = "ipfs://bafybeiad2zwj5cc7cazjnbpn4o7ggskeg2mbzz2cuybmqfud4e7pwvh6ha/"
const MyToken = require("../build/contracts/MyToken.json").abi;
const addressOwner = "0xeac9852225Aa941Fa8EA2E949e733e2329f42195";
const privateKey = process.env.MNEMONIC_WALLET.trim().toString();

async function mint() {
    const wallet = new ethers.Wallet.fromMnemonic(privateKey);
    const contract = new ethers.Contract(addressOfContract, MyToken, wallet);
      let name = await contract.name();
    console.log(name);   
}

mint();

it gives me this error in the console:

reason: 'missing provider',
  code: 'UNSUPPORTED_OPERATION',
  operation: 'call'

1 Answer 1

0

I already answered your same question here on Stack Overflow, but for easy access here's my answer:

You're getting this error because ethers.Contract() requires a signer or provider as the last argument, but you've provided a Wallet object.

If you connect your Wallet to a provider it should work. Using your example, it should look like this:

async function mint() {
   const wallet = new ethers.Wallet.fromMnemonic(privateKey);
   const walletWithProvider = wallet.connect(ethers.provider)
   const contract = new ethers.Contract(addressOfContract, MyToken, walletWithProvider);
   let name = await contract.name();
   console.log(name);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.