mirror of https://github.com/status-im/EIPs.git
Automatically merged updates to draft EIP(s) 1193
Hi, I'm a bot! This change was automatically merged because: - It only modifies existing Draft or Last Call EIP(s) - The PR was approved or written by at least one author of each modified EIP - The build is passing
This commit is contained in:
parent
2c6a87ce8f
commit
06480720ae
|
@ -12,11 +12,7 @@ requires: 1102
|
|||
|
||||
## Summary
|
||||
|
||||
This EIP formalizes an Ethereum Provider JavaScript API for consistency across clients and applications.
|
||||
|
||||
The provider is designed to be minimal containing 2 methods: `send` and `on`. It emits 5 types of events: `notification`, `connect`, `close`, `networkChanged`, and `accountsChanged`.
|
||||
|
||||
It is intended to be available on `window.ethereum`.
|
||||
This EIP formalizes an Ethereum Provider JavaScript API for consistency across clients and applications. The provider is designed to be minimal and is intended to be available on `window.ethereum` for cross environment compatibility.
|
||||
|
||||
## API
|
||||
|
||||
|
@ -34,11 +30,11 @@ See the [available methods](https://github.com/ethereum/wiki/wiki/JSON-RPC#json-
|
|||
|
||||
#### eth_requestAccounts
|
||||
|
||||
By default, the provider supplied to a new dapp has is a "read-only" provider with no accounts authenticated.
|
||||
By default, the provider supplied to a new dapp has is a "read-only" provider with no accounts authenticated. See [EIP 1102: Opt-in account exposure](https://eips.ethereum.org/EIPS/eip-1102).
|
||||
|
||||
To request accounts, call `ethereum.send('eth_requestAccounts')`. This will ask the user which account(s) they would like to authenticate to the dapp.
|
||||
|
||||
Promise resolves with an array of the account(s) addresses.
|
||||
Promise resolves with an array of the enabled account(s) addresses.
|
||||
|
||||
### Events
|
||||
|
||||
|
@ -101,15 +97,6 @@ ethereum.on('accountsChanged', listener: (accounts: Array<String>) => void): thi
|
|||
|
||||
The event emits with `accounts`, an array of the accounts' addresses.
|
||||
|
||||
### isEIP1193
|
||||
|
||||
`isEIP1193` is a public read-only value on the provider to help distinguish itself.
|
||||
|
||||
```js
|
||||
ethereum.isEIP1193;
|
||||
> true
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```js
|
||||
|
@ -242,6 +229,8 @@ If no accounts are authenticated, the `eth_requestAccounts` method **MUST** ask
|
|||
|
||||
The `eth_requestAccounts` method **MUST** resolve with an array of the account(s) addresses or reject with an `Error`. If the account(s) enabled by the provider change, the `accountsChanged` event **MUST** also emit.
|
||||
|
||||
For full specification of the `eth_requestAccounts` RPC method, see [EIP 1102: Opt-in account exposure](https://eips.ethereum.org/EIPS/eip-1102).
|
||||
|
||||
### Events
|
||||
|
||||
The provider **SHOULD** extend from `EventEmitter` to provide dapps flexibility in listening to events. In place of full `EventEmitter` functionality, the provider **MAY** provide as many methods as it can reasonably provide, but **MUST** provide at least `on`, `emit`, and `removeListener`.
|
||||
|
@ -266,13 +255,9 @@ If the network the provider is connected to changes, the provider **MUST** emit
|
|||
|
||||
If the accounts connected to the Ethereum Provider change at any time, the Ethereum Provider **MUST** send an event with the name `accountsChanged` with args `accounts: Array<String>` containing the accounts' addresses.
|
||||
|
||||
### isEIP1193
|
||||
|
||||
The provider **MUST** define `public readonly ethereum.isEIP1193: Boolean`
|
||||
|
||||
### web3.js Backwards Compatibility
|
||||
|
||||
If the implementing Ethereum Provider would like to be compatible with `web3.js` prior to `1.0.0-beta38`, it **MUST** provide two methods: `sendAsync(payload: Object, callback: (error: any, result: any) => void): void` and `isConnected(): Boolean`.
|
||||
If the implementing Ethereum Provider would like to be compatible with `web3.js` prior to `1.0.0-beta38`, it **MUST** provide the method: `sendAsync(payload: Object, callback: (error: any, result: any) => void): void`.
|
||||
|
||||
### Error object and codes
|
||||
|
||||
|
@ -296,7 +281,6 @@ class EthereumProvider extends EventEmitter {
|
|||
super();
|
||||
|
||||
// Init storage
|
||||
this._isConnected = false;
|
||||
this._nextJsonrpcId = 0;
|
||||
this._promises = {};
|
||||
|
||||
|
@ -307,10 +291,6 @@ class EthereumProvider extends EventEmitter {
|
|||
window.addEventListener('message', this._handleJsonrpcMessage.bind(this));
|
||||
}
|
||||
|
||||
static get isEIP1193() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
|
||||
send(method, params = []) {
|
||||
|
@ -404,12 +384,10 @@ class EthereumProvider extends EventEmitter {
|
|||
}
|
||||
|
||||
_emitConnect() {
|
||||
this._isConnected = true;
|
||||
this.emit('connect');
|
||||
}
|
||||
|
||||
_emitClose(code, reason) {
|
||||
this._isConnected = false;
|
||||
this.emit('close', code, reason);
|
||||
}
|
||||
|
||||
|
@ -438,10 +416,6 @@ class EthereumProvider extends EventEmitter {
|
|||
);
|
||||
});
|
||||
}
|
||||
|
||||
isConnected() {
|
||||
return this._isConnected;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue