I am building an oracle to watch for an event on one chain and respond by sending a transaction to another chain. Creating multiple instances of Web3 (version 1.0.0-beta.26) is fine but how do I create Contract objects with the correct provider? It seems to depend on the currentProvider of the last instantiated Web3 object rather than the currentProvider of the Web3 object used to build create contract object.

Suppose one chain is accessible on port 8546 and the other on 9546. I create two instances for web3:

web3a = new Web3('ws://localhost:8546');
web3b = new Web3('ws://localhost:9546');

But then if I try and get a contract on the a chain, it will try and talk to the b chain. e.g.

const someContract = new web3a.eth.Contract(...)

will log ws://localhost:9546, the b connection url rather than the a connection that I would expect.

Anybody know what I'm doing wrong or what I'm misunderstanding?

Your Answer

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

Browse other questions tagged or ask your own question.