Firebase Cloud Function calling a smart contract function

I’m developing a nft game and i need to reward the users in game token. In order to do that i have to call the Smart Contract Transfer function as the owner in a cloud function (problably using my private key). The problem is that i didn’t found any example showing how to do it.

Hi @EvandroAK

Can you share how your current code looks like? You most have to include the private as msg sender.

What i have is a function that can call contract functions:

interface RunContractFunctionData {

  chain: string;

  functionName: string;

  address: string;

  abi: unknown;

  params: { [name: string]: string };

}

export const runContractFunction = functions.https.onCall(

  async (data: RunContractFunctionData) => {

    const response = await Moralis.EvmApi.utils.runContractFunction({

      chain: data.chain,

      functionName: data.functionName,

      address: data.address,

      abi: data.abi,

      params: data.params,

    });

    return response.toJSON();

  });

But i don’t know how to use it to call a write function specifying the wallet that is the sender

Ahh ok. Moralis sdk is only for client side use so it needs connected wallet like metamask. To perform a backend contract call I would recommend using ether.js. This will have the option to specify your private key as signer

1 Like

Thank you, John. I’m on it.