Skip to content

Commit

Permalink
Merge pull request #3219 from ethereum/feature-request/requestAccounts
Browse files Browse the repository at this point in the history
eth_requestAccounts added to web3-eth package
  • Loading branch information
nivida committed Nov 21, 2019
2 parents ca9869f + 85dc0ee commit 0109937
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ Released with 1.0.0-beta.37 code base.

## [Unreleased]

## [1.2.4]
## [1.2.5]

### Added

- ``eth_requestAccounts`` as ``requestAccounts`` added to web3-eth package (#3219)

### Fixed
39 changes: 39 additions & 0 deletions docs/web3-eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,45 @@ Example
------------------------------------------------------------------------------

.. _eth-requestaccounts:

requestAccounts
=====================

.. code-block:: javascript
web3.eth.requestAccounts([callback])
This method will request/enable the accounts from the current environment it is running (Metamask, Status or Mist).
It doesn't work if you're connected to a node with a default Web3.js provider. (WebsocketProvider, HttpProvidder and IpcProvider)
This method will only work if you're using the injected provider from a application like Status, Mist or Metamask.

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>`_

----------
Parameters
----------

1. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.

-------
Returns
-------

``Promise<Array>`` - Returns an array of enabled accounts.

-------
Example
-------


.. code-block:: javascript
web3.eth.requestAccounts().then(console.log);
> ['0aae0B295369a9FD31d5F28D9Ec85E40f4cb692BAf', '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe']
------------------------------------------------------------------------------

.. _eth-chainId:

getChainId
Expand Down
6 changes: 6 additions & 0 deletions packages/web3-eth/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ var Eth = function Eth() {
params: 0,
outputFormatter: utils.hexToNumber
}),
new Method({
name: 'requestAccounts',
call: 'eth_requestAccounts',
params: 0,
outputFormatter: utils.toChecksumAddress
}),

// subscriptions
new Subscriptions({
Expand Down
3 changes: 3 additions & 0 deletions packages/web3-eth/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ export class Eth {
blockNumber: BlockNumber,
callback?: (error: Error, result: GetProof) => void
): Promise<GetProof>;

requestAccounts(): Promise<string[]>
requestAccounts(callback: (error: Error, result: string[]) => void): Promise<string[]>
}

export interface Syncing {
Expand Down
19 changes: 19 additions & 0 deletions test/eth.requestAccounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var testMethod = require('./helpers/test.method.js');

var method = 'requestAccounts';
var call = 'eth_requestAccounts';

var tests = [{
result: ['0x47d33b27bb249a2dbab4c0612bf9caf4c1950855', '0x11f4d0a3c12e86b4b5f39b213f7e19d048276dae'],
formattedResult: ['0x47D33b27Bb249a2DBab4C0612BF9CaF4C1950855', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'],
call: call
},
{
result: ['0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'],
formattedResult: ['0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe', '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe'],
call: call
}];


testMethod.runTests('eth', method, tests);

0 comments on commit 0109937

Please sign in to comment.