Connection between nodejs and metamask

Viewed 152
  1. 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.

  2. 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.

1 Answers
  1. 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

  1. Check the first link above
Related