0

So this is my users controller to upload a file :

exports.postUploadFile = (req, res, next) => {

    var ethereumURI = req.body.ethereumURI;
    var abi = JSON.parse(req.body.abi);
    var contractAddress = req.body.contractAddress;
    let web3 = new Web3();
    web3.setProvider(new web3.providers.HttpProvider(window.web3.currentProvider));
    . . .
}

as you can see when i set my provider with "window.web3.currentProvider" instead of to make my metamask pop up, i got an error "window is undefined" ?

So how to use "window" for backend in node js / express js? I am using web3.js (0.2.x)

1

Shortly, you cannot.

window is defined only in a browser environment. In your case, since you're running it through Nodejs, window is undefined as expected.

  • Hmm that's too bad, im just wanna make my metamask pop up to confirm when i deployed my contract or using some function with ... So is there any solution, to make my metamask pop up for transaction confirmation with Nodejs? – Dzaky Badawi Jul 14 at 15:21
  • the popup is client side not server side. You can do moving your code on the client side which may be the correct place given your requirement – mirg Jul 14 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.