I can easily interact with metamask via web3 js like this (JS):

web3 = new Web3(web3.currentProvider);

Is it possible to interact with metamask via php? For example (PHP):

$ethereum = new Ethereum('', 8545);

Javascript equivalent (JS):

web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

But the PHP one posted above can only connect to a server node via IP address and I'm not sure if its possible / how to connect with a metamask user in PHP.

I dont think its possible because PHP is server side but if anyone has some insight on this I would appreciate it..

  • 1
    No, what you describe is not possible.
    – user19510
    Commented Feb 24, 2018 at 0:32

1 Answer 1


No, this is not possible. PHP is executed on the server, JavaScript is executed in the browser. PHP could theoretically connect to a node that you run yourself on your own server, but not to a node on the client or to a browser add-on.

  • 2
    Duplicate ethereum.stackexchange.com/questions/13826/… PHP connects via JsonRPC to a Ethereum node. Commented Mar 21, 2018 at 0:13
  • I have some idea how this could be done. First, you create a WebSocket server on the server-side (PHP). You then connect client-side (JavaScript in the browser) to that WebSocket. You then make (on client-side) some kind of proxy that forwards all requests from WebSocket to Web3 provider (MetaMask) and return the result. And on server-side, you then send Web3 requests to WebSocket and read results from it. So, basically, all requests from the server are forwarded to the client and executed with MetaMask and result is then forwarded back to the server.
    – Filip Š
    Commented Jul 14, 2019 at 15:13
  • @FilipŠ PHP typically finishes executing on the server before the page content gets transmitted to the browser and before any client-side JS runs. If you really need to control MetaMask from the server (you probably don't), choose a different webserver or framework. Commented Jul 14, 2019 at 15:45
  • @Grunzwanzling I was thinking this if there would be another continuos PHP process with WebSocket server. But this obviously won't work for normal setups with Apache or another server.
    – Filip Š
    Commented Jul 14, 2019 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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