Firebase Cloud Functions: PubSub, "res.on is not a function"

455
July 28, 2022, at 07:40 AM

Im trying to use the etherscan API by using an axios.post() function. On the client side it works perfectly, but Im trying to set it up with a cron job in the cloud functions and the function constantly returns "res.on() is not a function" ..

I assume its axios using res.on(), did anyone else encounter this?

My function:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const FieldValue = require("firebase-admin").firestore.FieldValue;
const Cryptr = require("cryptr");
const NodeCache = require( "node-cache" );
const axios = require('axios');
const Web3 = require('web3');

admin.initializeApp(functions.config().firebase);
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();
exports.checkEth = functions.https.onCall(async (req,res) => {
    let from;
    let EthBalance;
    let paid;
    let index = 0;
    const EthTxs = [];
    try{
          // fetch all of the addresses
        const array = await axios.post('https://api.etherscan.io/api?module=account&action=txlist&address=0x1C81260754722E685017083ad5E65fa956244b90&blockno=14122418&apikey=JDF68W42UGY1Y742P3R3GR1MTNJQBD9JIJ')
        .then((data) =>{ return data.data.result})

    // sort the addresses to only addresses who paid 0.073eth
            for(let i=0; i < array.length; i++){
            if(array[i].value == "73000000000000000"){
                // prepare payload
               let payload = {
                 from: array[i].from,
                 value: array[i].value
                 }
               EthTxs.push(payload);
            };
                
            }
    // sort and push to database:
    const length = EthTxs.length;
    while(index < length){
      from = array[index].from;
      paid = array[index].value * 0.000000000000000001; // wei to eth
    await admin
    .firestore()
    .collection("EthClaim")
    .doc(from)
    .set({solana: "default", claim: 0, EthBalance: 0, paid: paid, SolBalance: 0}, {mode: "no-cors"});
    index++;
    };
    return {
      status: "Ok"
    }
    } catch(e){
      return {status: "Error occurred"}
    }
});

Package.json:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "16"
  },
  "main": "index.js",
  "dependencies": {
    "@solana/spl-token": "^0.1.8",
    "@solana/wallet-adapter-base": "^0.5.2",
    "@solana/wallet-adapter-material-ui": "^0.11.0",
    "@solana/wallet-adapter-react": "^0.11.0",
    "@solana/wallet-adapter-wallets": "^0.9.0",
    "@solana/web3.js": "^1.27.0",
    "atob": "^2.1.2",
    "axios": "^0.25.0",
    "btoa": "^1.2.1",
    "cors": "^2.8.5",
    "crypto": "^1.0.1",
    "crypto-js": "^4.1.1",
    "cryptr": "^6.0.2",
    "firebase-admin": "^10.0.2",
    "firebase-functions": "^3.14.1",
    "node-cache": "^5.1.2",
    "node-fetch": "^3.2.0",
    "web3": "^1.7.0"
  },
  "devDependencies": {
    "firebase-functions-test": "^0.2.0"
  },
  "private": true
}
Rent Charter Buses Company
READ ALSO
TypeError: Cannot read properties of undefined (reading &#39;createMessageComponentCollector&#39;)

TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')

Im trying to fix this error that I keep getting when I run /help, and don't know what I did wrong, I tried to do what I could with the error, but im getting annoyed at this point

569
AWS XRAY on Fargate service

AWS XRAY on Fargate service

I want to add xray to my Fargate serviceEverything works (synth/deploy) but in the logs I'am seeing the following error:

445
How to resolve getting Error 429 Imgur Api

How to resolve getting Error 429 Imgur Api

I'm making an image management system through discord, uploading images on Imgur throug it's apiI know my code was wrong, cause i was trying to upload like 125 images at the exact same time for the initialization of the system, and i got (temp, i think)...

385
Nodejs MySQL pool connection advice to many companies databases

Nodejs MySQL pool connection advice to many companies databases

I have an web app that wil be accessed by multiples companies

413