[SOLVED] Unable to use Moralis.provider in web3JS

const web3JS = new Web3(Moralis.provider);
const ERC1155ContractInstance = await new web3JS.eth.Contract( ERC1155.abi, contractAddress, Moralis.provider);
const NFTMintingResponse = await ERC1155ContractInstance.methods.mint(
        wallet,
        Number(artwork.token_id),
        Number(quantity), // quantity,
        "0x" // any data
     ).send({from: wallet});

After this the user’s address is going zero, this is the error I get

"execution reverted: AccessControl: account 0x0000000000000000000000000000000000000000 is missing role 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6"

What is the contract address and chain? Have you enabled web3 e.g. with Moralis.enableWeb3() or authenticated?

That account shouldn’t be zero in that error, do you get the transaction to sign in your wallet?

I have called the above like this

const handleEnableWeb3 = async() => {
    if(isInitialized) {
      try {
        const chainId = await Moralis.getChainId();
        const provider = await Moralis.enableWeb3({
          chainId: chainId
        })
        console.log(await provider.ready)
      } catch (err) {
        console.error(err)
      }
    }
  }

Screenshot 2022-08-24 at 8.32.17 PM

I have authenticated using metamask, and after calling the contract the address is zero and throws this kind of error in on of my contract call which uses wallet address inside

"execution reverted: AccessControl: account 0x0000000000000000000000000000000000000000 is missing role 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6"

What is the value of the wallet parameter?

Could be due to your web3.js code. To test, you could try using executeFunction which uses ethers.js with the same parameters to see if the result is different. You can also call mint directly on your contract on mumbai.polygonscan.com to test.

What is the contract address and chain? Is this your own contract?

wallet value is an address of the user basically got from account value from react-moralis

Contract address - 0xF4045d037aE1dEb14754694F55AE4Fda0a3D15f0
Chain Polygon Mumabai Testnet

Tried with execFunction still the error remains same, I want the this functionality working inside the application, it was working fine with infura provider but after switching to moralis this issue poped up

"execution reverted: AccessControl: account 0x0000000000000000000000000000000000000000 is missing role 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6"

Mint code looks like this now

const sendOptions = {
        contractAddress: contractAddress,
        functionName: "mint",
        abi: ERC1155.abi,
        params: {
          account: wallet,
          id: Number(artwork.token_id),
          amount: Number(quantity),
          data: "0x"
        },
      }
      const transaction = await Moralis.executeFunction(sendOptions);
      console.log(await transaction.wait());

it was working fine with infura provider but after switching to moralis

What did you do before exactly? It shouldn’t be any different because it will just use your wallet’s chain settings (RPC). executeFunction just uses ethers.js.

It was an issue with gas estimation function, provider from react-moralis didn’t work and I resolved it by using infura provider

1 Like