Connection between nodejs and metamask - node.js

When I tried to create a connection between nodejs and metamask, facing window object not found issue.So, how can we connect nodejs and metamask? Please share the supported package.
How to sign a transaction and save the data in blockchain using the user current account fetched from the metmask in nodejs? And any code snippet would helpful for reference.

Metamask is only available as a browser extension and mobile app. Your node js app won't run in the browser environment so it's not possible to connect to your browser metamask app with your node js app. What you can do is export your metamask private key to your environment variable and then use your node js app to send transactions to the blockchain with your metamask account. (I would advise to do so only if you are doing it on testnet, if someone can get access to your private key of mainnet account they can steal all the assets associated with the account)
Here's an example: Send Transaction with node js from your account example
Export private key from metamask: https://metamask.zendesk.com/hc/en-us/articles/360015289632-How-to-export-an-account-s-private-key
Check the first link above

Related

How to use strapi provider Microsoft in expo react native?

I have been trying to use my Microsoft azure login through the strapi provider. If I pass in the link to mywebsite/api/microsoft in a browser am able to see the login process and the user is available in my strapi dashboard.
But how do set up this in my expo react native app?
If i insert the link with authsession or Webbrowser, I can't close the browser after the login page is finished, so I am not able to check if the user is logged in, or get the data from the login because every time I close the browser I only get that the login was canceled.
I have been trying to follow this guide from their docs, but i can't find a solution that works
guide to frontend setup for Cas setup from strapi docs

How can you use firestore's onSnapshot listener when the firestore method is being called from node.js?

I have an admin site that has a react frontend, using redux actions, with a node.js app as the server which uses firebase-admin to do the work.
I want to use firestore's onsnapshot listener. but im not sure how this works within the HTTP protocol?
I can't use the firebase-admin from my frontend app, and i cant create realtime DB functionality from the backend within HTTP protocol.
The goal: to set snapshot listeners on my collections from rreact frontend without having to go through multiple authentication processes, considering ive got a separate auth system for admins with my express api.
Is there a solution for this?
EDIT:
my client app is currently initialized with firebase web app config data, but because im authenticating admins with my own express server, the firebase web SDK hasnt authenticated with firebase, so i dont have permission for the data i need. im not sure if i need a service account, or a web app config with extra setup or what
My recommendation is to integrate the Firebase JS SDK into your client app using signInWithCustomToken().
It's not too complicated to do. Though I suppose that depends a lot on how your current auth setup works.
The general idea is this:
Send auth request to your auth service.
Process the request like normal.
Evaluate if the user should have access to Firebase.
If they should, use firebase-admin to create a custom token and send it back to the user.
Use the token on the client to authenticate with Firebase.auth
You should make sure to have Firestore rules to allow admin users to access the data you need.
As an alternative that doesn't use the Firebase client SDK, you could have a long-running node process that opens an onSnapshot. Your react app could receive data from it using either Server-Sent Events or through a WebSocket

How to get OAuth2 token from an EC2 instance with no browser using nodejs google api

I have a node.js app that uses the google drive API to upload a file to a google drive. It is working fine on my local machine. I am now trying to migrate it to an EC2 instance but when I run the app using node, I am unable to verify by visiting the url...
Authorize this app by visiting this url: https://accounts.google.com/o/oauth2/v2/auth?>access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&cl>ient_id=xxxxxxxxxxxx.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoo>b
Not sure how to proceed as there is no browser on the machine - which makes me question if I am using the correct protocol for this application? I get totally confused by all the different options available.
I am basically using the option laid out here: https://developers.google.com/docs/api/quickstart/nodejs
Any pointers would be greatly appreciated.
Following the steps from the NodeJs Drive API quickstart, you can run your application locally the first time, this way the consent screen will be prompted and you'll be able to grant the permissions. With this, a token.json file will be created in your directory which will be used to create refresh tokens used to authorize the subsequent requests. You can upload your application to the EC2 instance with the token.json file included and you won't have to authorize the application again.
You can read more about refreshing an access token with offline access in Google's OAuth documentation.

RESTful api method to verify user's email id , activate account and reset password

I want to send a link to the email address for account verification and to reset the password. Later I had a frontend+backend structure, I want to know how can I do this in REST api way. If I host 2 frontend app in https://example1.com and https://example2.com how can I write a flexible backend in nodejs
Part 1: Sending Emails
To send emails, you need to have an SMTP server. For SMTP server, you can either configure one by your own or subscribe for email services like sendgrid.
Sendgrid provides APIs, which allows you to send transactional or promotional emails.
Part 2: Middleware
You may have to rent a linux server, install Node JS on it and use Express JS for developing and deploying the backend with REST API support. Your frontend apps https://example1.com and https://example2.com can be hosted using Apache and they can communicate to the middleware which is developed using Express JS.
Part 2: Database Connectivity from Middleware
You can install MariaDB in server and connect your node js program to MariaDB using the node module mysql.
This is just a high level advice. You will have to spend some time yourself to get everything configured and wired, or take the help of experienced engineers.

Cordova - Best approach to save images in Nodejs

I'm building a Cordova App that connects to a NodeJS Api. In the middle I have added Firebase to help me out with Authentication.
Now I want to store user's images into some server. What would it be the best approach?
a) Firebase storage: User will send image file to Firebase Storage and my nodeJS server will fetch that image's link and stores into Mondodb.
b) Send the image directly to Nodejs and it will save it somewhere else (e.g Google cloud, Azure)
What do you think?

Resources