Migrate from classic web3 to moralis way

So I have this working code:

const ethers = new Web3(web3.provider);
  const contract = new ethers.eth.Contract(contractAbi, CONTRACT_ADDRESS);
  contract
    .methods
    .mint(address, tokenId, amount)
    .send({from:account, value: 0 })
    .on("receipt", function(receipt) {
        console.log(receipt);
    })

Currently I’m trying to convert it to more “Moralis” way – using the library:

First example:

const lib = Moralis.web3Library;
  const signer = web3.getSigner();
  const contract2 = new lib.Contract(CONTRACT_ADDRESS, contractAbi, signer);
  const minting = await contract2.mint(address, tokenId, amount)

this will return MetaMask - RPC Error: execution reverted: Ownable: caller is not the owner

Second example:

const sendOptions = {
    contractAddress: CONTRACT_ADDRESS,
    functionName: "mint",
    abi: contractAbi,
    contractAddress: CONTRACT_ADDRESS,
    chain: 'rinkeby',
    params: {account: address, id: tokenId, amount}
  };
  const contract = await Moralis.executeFunction(sendOptions);
console.log(contract)

will return Error: cannot estimate gas; transaction may fail or may require manual gas limit


Any solution / insight how to make both examples works?

Thanks

The first example seems like you aren’t on the right account (since it says you aren’t the owner, I am guessing you have onlyOwner on your mint function)

And for the second example you have contractAddress specified twice, maybe that is what is bothering it?