Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 0109937

Browse files
authored
Merge pull request #3219 from ethereum/feature-request/requestAccounts
eth_requestAccounts added to web3-eth package
2 parents ca9869f + 85dc0ee commit 0109937

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ Released with 1.0.0-beta.37 code base.
9898

9999
## [Unreleased]
100100

101-
## [1.2.4]
101+
## [1.2.5]
102102

103103
### Added
104104

105+
- ``eth_requestAccounts`` as ``requestAccounts`` added to web3-eth package (#3219)
106+
105107
### Fixed

docs/web3-eth.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,45 @@ Example
17111711
17121712
------------------------------------------------------------------------------
17131713

1714+
.. _eth-requestaccounts:
1715+
1716+
requestAccounts
1717+
=====================
1718+
1719+
.. code-block:: javascript
1720+
1721+
web3.eth.requestAccounts([callback])
1722+
1723+
This method will request/enable the accounts from the current environment it is running (Metamask, Status or Mist).
1724+
It doesn't work if you're connected to a node with a default Web3.js provider. (WebsocketProvider, HttpProvidder and IpcProvider)
1725+
This method will only work if you're using the injected provider from a application like Status, Mist or Metamask.
1726+
1727+
For further information about the behavior of this method please read the EIP of it: `EIP-1102 <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1102.md>`_
1728+
1729+
----------
1730+
Parameters
1731+
----------
1732+
1733+
1. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.
1734+
1735+
-------
1736+
Returns
1737+
-------
1738+
1739+
``Promise<Array>`` - Returns an array of enabled accounts.
1740+
1741+
-------
1742+
Example
1743+
-------
1744+
1745+
1746+
.. code-block:: javascript
1747+
1748+
web3.eth.requestAccounts().then(console.log);
1749+
> ['0aae0B295369a9FD31d5F28D9Ec85E40f4cb692BAf', '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe']
1750+
1751+
------------------------------------------------------------------------------
1752+
17141753
.. _eth-chainId:
17151754

17161755
getChainId

packages/web3-eth/src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@ var Eth = function Eth() {
483483
params: 0,
484484
outputFormatter: utils.hexToNumber
485485
}),
486+
new Method({
487+
name: 'requestAccounts',
488+
call: 'eth_requestAccounts',
489+
params: 0,
490+
outputFormatter: utils.toChecksumAddress
491+
}),
486492

487493
// subscriptions
488494
new Subscriptions({

packages/web3-eth/types/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ export class Eth {
364364
blockNumber: BlockNumber,
365365
callback?: (error: Error, result: GetProof) => void
366366
): Promise<GetProof>;
367+
368+
requestAccounts(): Promise<string[]>
369+
requestAccounts(callback: (error: Error, result: string[]) => void): Promise<string[]>
367370
}
368371

369372
export interface Syncing {

test/eth.requestAccounts.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var testMethod = require('./helpers/test.method.js');
2+
3+
var method = 'requestAccounts';
4+
var call = 'eth_requestAccounts';
5+
6+
var tests = [{
7+
result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae'],
8+
formattedResult: ['0x47D33b27Bb249a2DBab4C0612BF9CaF4C1950855', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'],
9+
call: call
10+
},
11+
{
12+
result: ['0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'],
13+
formattedResult: ['0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'],
14+
call: call
15+
}];
16+
17+
18+
testMethod.runTests('eth', method, tests);
19+

0 commit comments

Comments
 (0)