Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Add notes when creating a server and accesing the provider #403

Merged
merged 3 commits into from
Jul 3, 2019

Conversation

lopezjurip
Copy link
Contributor

Using .server() and .provider() at the same time can lead to unexpected behavior and it's prone to bugs

const ganache = require("ganache-core");
const server = ganache.server();
const provider = ganache.provider(); // parallel "blockchain" 

To avoid problems this is the way it should be used:

const ganache = require("ganache-core");
const server = ganache.server();
const provider = server.provider

Using `.server()` and `.provider()` at the same time can lead to unexpected behavior and it's prone to bugs

```js
const ganache = require("ganache-core");
const server = ganache.server();
const provider = ganache.provider(); // parallel "blockchain" 
```

To avoid problems this is the way it should be used:

```js
const ganache = require("ganache-core");
const server = ganache.server();
const provider = server.provider
```
@davidmurdoch
Copy link
Member

Thanks for the idea, @lopezjurip. Creating two instances of a provider is a use-case we want to allow and is expected behavior.

server.provider is an undocumented property and should not be relied upon. We don't currently expose the server's underlying provider instance as part of the public interface so I'm hesitant to do so now without giving it much more thought.

@lopezjurip
Copy link
Contributor Author

@davidmurdoch i agreed on creating multiple instances, the only problem is when you want to use the same provider after creating the server in the same process. The documentation is a little misleading because it's not showing how to create a web3 instance after creating the server while using the same "blockchain"

@davidmurdoch
Copy link
Member

@lopezjurip Are you wanting to connect to the ws/http server via Web3 or to the in-process provider directly?

@lopezjurip
Copy link
Contributor Author

@davidmurdoch both. I was trying to expose the server to the outside but also being able to operate over it from the inside (same process) with web3. So after reading the docs I was using ganache.server(); and ganache.provider() thinking it was the correct way of using and exposing the same blockchain, but took me a while to realize i got 2 blockchains running in parallel.

So that's why I think it should be documented how to access the provider after creating the server.

@davidmurdoch davidmurdoch merged commit d6b4a91 into trufflesuite:develop Jul 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants