Is it normal/possible to use 2 instances of the web3 object?

In my app, a user can

  • trigger the deployment of new contracts by clicking a button on the UI. The gas comes from a wallet that belongs to the app
  • send ether to the deployed contract on the same page (made simple via a button on the page, contract then sends tokens to user)

In this scenario, is it recommended to have 2 web3 instances,

  1. one using the web3 belonging to the app
  2. one injected by the user's browser (eg: Metamask)

If so, is there a naming convention for the 2 web3 instances, like web3App and web3Browser?

Is this also an unusual scenario?

1 Answer 1


Yes it is possible to run 2 instances of web3.js. I am not aware of any naming convention for each web3 instance.

On the readme of web3 on github (https://github.com/ethereum/web3.js/blob/develop/README.md), there are some instructions to run several instances of web3:

web3.js version 0.14.0 supports multiple instances of web3 object. To migrate to this version, please follow the guide:

var Web3 = require('web3');
var web3 = new Web3();

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.