Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth_requestAccounts added to web3-eth package #3219

Merged
merged 3 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[]>
cgewecke marked this conversation as resolved.
Show resolved Hide resolved
}

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);