docs(@emabrk/site): add docs for dappConnection

This commit is contained in:
Jonathan Rainville 2019-08-12 11:27:52 -04:00 committed by Iuri Matias
parent 12d13f8411
commit ec8f8fa39e
3 changed files with 28 additions and 9 deletions

View File

@ -17,11 +17,6 @@ Let's take a look at the `config/contracts.js` file that we've created in the [Q
```
module.exports = {
default: {
deployment: {
host: "localhost",
port: 8546,
type: "ws"
},
dappConnection: [
"$WEB3",
"ws://localhost:8546",
@ -37,7 +32,7 @@ module.exports = {
}
```
Don't get too overwhelmed by all the different options and what they mean. We'll discuss those in-depth in [configuring Smart Contracts](contracts_configuration.html). The important part here is that `contracts.js` exports an object that provides a `default` configuration. This configuration is the default environment and can be overwritten or extended by other environments.
Don't get too overwhelmed by all the different options and what they mean. We'll discuss those in-depth in [configuring Smart Contracts](contracts_configuration.html) and `dappConneciton` [here](/docs/javascript_usage.html#Using-dappConnection). The important part here is that `contracts.js` exports an object that provides a `default` configuration. This configuration is the default environment and can be overwritten or extended by other environments.
If we execute `$ embark run`, Embark will use the `default` configuration to deploy our application's Smart Contracts.

View File

@ -18,8 +18,8 @@ Let's see what that generated config file looks like at `embarkArtifacts/config/
{
"dappConnection": [
"$WEB3",
"ws://localhost:8546",
"http://localhost:8545"
"$EMBARK",
"ws://localhost:8546"
],
"dappAutoEnable": true,
"warnIfMetamask": true,
@ -30,7 +30,7 @@ Let's see what that generated config file looks like at `embarkArtifacts/config/
#### Connection parameters:
- **dappConnection**: Copied from the contracts config. This is the list of connections Embark will try to connect to in order.
- **dappConnection**: Copied from the contracts config. This is the list of connections Embark will try to connect to in order. For more information, look at [the guide on EmbakJS](/docs/javascript_usage.html#Using-dappConnection).
- **dappAutoEnable**: Copied from the contracts config. This tells EmbarkJS to either automatically connect to Metamask (or Mist) or wait for the developper (you) to do it.
- Read more on it [below](#Provider)
- **warnIfMetamask**: Is true when `isDev` is true in the blockchain config. Will warn you in the console if Metamask is detected, to make sure you connect Metamask correctly to the local node.

View File

@ -43,6 +43,30 @@ EmbarkJS.onReady((error) => {
});
```
## Using `dappConnection`
After reading the section above on `EmbarkJS.onReady`, you might be wondering, but where does EmbarkJS connect?
The answer is: you decide! You can configure it using `dappConnection`, a config property you can find in the Contracts config (by default at `config/contracts.js`).
You will notice that property name reused in some other config files too, like the Storage one, because you can configure where those connect too.
`dappConnection` is a bit weird, but is quite simple. It's an array of strings where EmbarkJS will try each of those in order (from 0 to N) and as soon as one of the connections work, it will stop.
In the case of the Contracts config `dappConnection`, the one that is used to connect to the blockchain node and that is indirectly used in `EmbarkJS.onReady`, you will see two special entities: `$WEB3` and `$EMBARK`.
- `$WEB3` tells EmbarkJS to connect to the browser's web3 instance. For example, Metamask or Status.
- `$EMBARK` tells EmbarkJS to connect to Embark's wallet, implemented using a proxy in between the Dapp and the blockchain node.
- This let's you use you own accounts, as set up in your Blockchain config's `accounts` section
- If you don't use custom accounts, using `$EMBARK` is still useful, because it connects to the node more easily for you and uses the unlocked accounts on the node, like when using the `dev` `miningMode`
- Also, Embark gets to see the transactions processed and logs them back to you in a human readable manner
If you want, you can also put a valid node URL in the `dappConnection` array. In that case, EmbarkJS will connect directly to the node, without using Embark's proxy.
It is, however, not recommended as you lose some of Embark's features, like the transaction logger.
If you want to use an external node, like Infura, we instead recommend to set it in the Blockchain config (`config/blockchain.js`) using the property `endpoint`.
Then, using `$EMBARK` will use Embark's proxy, which in part will be connected to that endpoint.
## Requesting account access
As of [EIP1102](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1102.md), decentralized applications MUST request access to a DApp's user accounts. Embark offers several options on how to implement this.