[SOLVED] Cannot use http.onRequest cloud functions with Moralis in Firebase project

Hey! I’m following your tutorial here: https://docs.moralis.io/docs/using-firebase except for that I want to use the cloud function http.onRequest instead of .onCall as you have in the example. However, I’m getting this error when I’m trying to build:

src/index.ts:23:7 - error TS2322: Type ‘string | string[] | ParsedQs | ParsedQs[] | undefined’ is not assignable to type ‘EvmAddressish’.
Type ‘undefined’ is not assignable to type ‘EvmAddressish’.

23 address: address,


node_modules/@moralisweb3/common-evm-utils/lib/operations/balance/getNativeBalanceOperation.d.ts:11:5
11 address: EvmAddressish;

The expected type comes from property ‘address’ which is declared here on type ‘GetNativeBalanceRequest’

This is my code:

import * as functions from "firebase-functions";

import * as admin from "firebase-admin";

import {EvmChain} from "@moralisweb3/common-evm-utils";

import Moralis from "moralis";

admin.initializeApp(functions.config().firebase);

Moralis.start({

  apiKey: "my_api_key",

});

// // Start writing functions

// // https://firebase.google.com/docs/functions/typescript

export const getBalance = functions.https.onRequest(async (req, res) => {

    const address = req.query.address;

    const result = await Moralis.EvmApi.balance.getNativeBalance({

      chain: EvmChain.ETHEREUM,

      address: address,

    });

    const usd = result.raw;

    res.json({usd});

  });

You can try something like:

const address = req.query.address as EvmAddressish;

or similar to the any type given when you use functions.https.onCall:

const address = req.query.address as any;

The last line there “…as any” worked great. Thank you very much!

1 Like