I want to set web3 to Metamask. As mentioned in Metamask document and npmjs, i took a use @metamask/detect-provider
. My problem is when i approach window.ethereum
. I have a UI, JS file, and some contracts. My app.js
code is below. Whenever my http request is /send-to-ipfs
i approach this message in console:
@metamask/detect-provider: Unable to detect window.ethereum.
Please install MetaMask!
Please check my app.js
code and comment about am i coding correct to set Metamask
as web3 provider or not, and in that case guide me to correct code.
app.js:
const fs = require("fs");
const ipfsClient = require('ipfs-http-client');
const Hash = require('ipfs-only-hash')
const contract=require("truffle-contract");
const Web3 = require("web3");
const Window = require('window');
const window = new Window();
const detectEthereumProvider=require('@metamask/detect-provider');
const solc=require("solc");
const express=require('express');
const app=express();
const bodyParser=require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));
app.use(express.static('E:/Test'));
app.set('view engine',"pug");
app.set('views','./views');
app.post('/send-to-ipfs', async function(q,r){
const node= ipfsClient({ host: 'localhost', port: '5001', protocol: 'http' });
const data=q.body.KeyPad;
let result=await Hash.of(data)
node.add(data);
const provider=await detectEthereumProvider();
if (provider) {
startApp(provider); // initialize your app
} else {
console.log('Please install MetaMask!');
}
r.render('IPFSconnection2.jade',{key: data, cid:result});
});
... here is some code that are not my peoblem ...