[SOLVED] How to call a contract write method from cloud functions?

Hi,

I try to call a write method from the cloud function. I’ve constructed this code from the documentation, but it does nothing when I call it (no errors). What am I missing?

Moralis.Cloud.define("triggerPayout", async () => {
const web3 = new Moralis.Web3(

      new Moralis.Web3.providers.HttpProvider(

        "https://polygon-mumbai.infura.io/v3/c687e0d06507410087cf869bee609b07"

      )

    );

    const engineAbi = [

// my contract's abi is here

    ];

    const address = "0x681B74792aC09d87e96834CbA82469fdd912878E";

    const contract = new web3.eth.Contract(engineAbi, address);

    await contract.methods.payWinner().call().catch((e) => logger.error(`callName: ${e}${JSON.stringify(e, null, 2)}`));;
}

I call it like this:

  const triggerCloudPayout = async () => {
    await Moralis.Cloud.run("triggerPayout");
  }

Thank you

usually, when you want to call a write method, you use .send() and you also need a private key that will be used to sign that transaction

1 Like

I’ll do it on the front end then. Thank you.

1 Like