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

Commit 8ac5c0e

Browse files
joshstevens19nivida
authored andcommitted
Types back-port from 2.x with changes to match the 1.x logic (#3132)
* docs: update readme to contain TS usage * feat: learna dtslint * feat: types for `web3` module * feat: `web3` module install dtslint * docs: readme web3 module types * feat: `web3-core` types * docs: update readme for `web3-core` for types * feat: install type dependencies for `web3-core` * feat: `web3-core-helper` types * feat: install type dependency for `web3-core-helpers` * docs: update readme for typings * fix: remove @types/node from `web3-core-helpers` * feat: `web3-core-method` types * feat: install type dependencies for `web3-core-method` * docs: update types for `web3-core-method` in readme * feat: `web3-eth` typings * feat: install type dependencies for `web3-eth` * docs: update readme for `web3-eth` * feat: `web3-eth-abi` typings * feat: install type dependencies for `web3-eth-abi` * docs: update readme for `web3-eth-abi` * feat: `web3-eth-accounts` typings * feat: install type dependencies for `web3-eth-accounts` * docs: update readme for `web3-eth-accounts` * feat: `web3-eth-contract` typings * feat: `web3-eth-contract` tests * feat: install types dependencies for `web3-eth-contract` * docs: update readme for `web3-eth-contract` * feat: `web3-eth-ens` typings * test: `web3-eth-ens` tests * feat: install type dependencies for `web3-eth-ens` * docs: update readme for `web3-eth-ens` * feat: `web3-eth-iban` typings * test: `web3-eth-iban` typing tests * feat: install `web3-eth-iban` typings dependencies * docs: update readme for `web3-eth-iban` * feat: `web3-eth-personal` typings * test: `web3-eth-personal` typings tests * feat: install dependencies for `web3-eth-personal` * docs: update readme `web3-eth-personal` * feat: `web3-net` typings * fix: remove dev dependencies which are not relavant * test: `web3-net` typings tests * docs: update readme for `web3-net` * feat: install dev dependencies for `web3-net` * feat: `web3-shh` typings * test: `web3-shh` typings tests * docs: update `web3-shh` readme * feat: install dev dependencies in `web3-shh` * feat: web3-utils type config files * feat: ascii to hex typings test * feat: bytes to hex typings test * feat: check address checksum typings test * feat: from ascii typings test * feat: from decimal typings test * feat: from utf8 typings test * feat: from wei typings test * feat: get signature params typings test * feat: get unit value typings test * feat: hex to ascii typings test * feat: hex to bytes typings test * feat: hex to number string typings test * feat: hex to number typings test * feat: hex to string typings test * feat: hex to utf8 typings test * feat: is address typings test * feat: is big number typings test * feat: is bloom typings test * feat: is bn typings test * feat: is hex strict typings test * feat: is hex typings test * feat: is topic typings test * feat: json interface method to string typings test * feat: keccak256 typings test * feat: left pad typings test * feat: number to hex typings test * feat: utils type tests * feat: add types in package.json * feat: new lock files for all packages * feat: new lock files for web3-eth-account * feat: new lock file for web3-provider.ws * feat: install new dev dependencies for typings on root * feat: export the typings in the package.json * feat: web3 typings tests to reference web3-core * feat: reference web3-core over web3-providers * feat: typings moved around due to different approach in 2.x * feat: web3-bzz types * feat: web3-bzz dependencies * test: web3 bzz types * fix: resolve dtslint typing tests fails * feat: web3-provider-http types * test: web3-provider-http tests * refactor: rename to `tests` * docs: add author to the http provider * feat: install web3-provider-ipc new dev dependencies * docs: update readme for web3-provider-ipc * feat: `web3-providers-ipc` typings * test: web3-provider-ipc test typings * feat: typings for web3-providers-ipc * fix: remove file comment * fix: resolve index.d.ts file * feat: install type dependencies for web3-provider-ws * feat: `web-providers-ws` typings * feat: web3-providers-ws ts files * test: web3-provider-ws-tests * fix: remove batch request from web3-bzz * feat: export errors from web3-core-helpers * fix: remove options from `web3.shh` * fix: define callback in the filter methods * feat: remove `TransactionSigner` * docs: add web3-eth-personal docs * fix: resolve typings 1.0 from pr comments * types updated * ci script updated * global install of typescript for CI added * installation of typescript moved to before_script * lerna-debug.log added to gitignore * lerna-debug removed * getNodeInfo added to types and documentation * getChainId to types added * travis.yml fixed * global install of typescript removed and just added as dependency to the root package.json * fix: dtslint to version `0.4.2` * fix: remove repeating typings
1 parent 03ed119 commit 8ac5c0e

File tree

185 files changed

+15179
-2145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+15179
-2145
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ bower_components
1515
.vscode/
1616
dist/
1717
packages/web3/dist/
18+
lerna-debug.log
1819
!./dist/web3.min.js

README.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
This is the Ethereum [JavaScript API][docs]
1111
which connects to the [Generic JSON RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC) spec.
1212

13-
1413
You need to run a local or remote [Ethereum](https://www.ethereum.org/) node to use this library.
1514

1615
Please read the [documentation][docs] for more.
@@ -31,15 +30,15 @@ yarn add web3
3130

3231
### Meteor
3332

34-
*Note*: works only in the Browser for now. (PR welcome).
33+
_Note_: works only in the Browser for now. (PR welcome).
3534

3635
```bash
3736
meteor add ethereum:web3
3837
```
3938

4039
### In the Browser
4140

42-
Use the prebuild ``dist/web3.min.js``, or
41+
Use the prebuild `dist/web3.min.js`, or
4342
build using the [web3.js][repo] repository:
4443

4544
```bash
@@ -76,40 +75,39 @@ web3.setProvider(new Web3.providers.WebsocketProvider('ws://localhost:8546'));
7675
There you go, now you can use it:
7776

7877
```js
79-
web3.eth.getAccounts()
80-
.then(console.log);
78+
web3.eth.getAccounts().then(console.log);
8179
```
8280

8381
### Usage with TypeScript
8482

85-
Type definitions are maintained at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) by others. You can install them with:
86-
87-
```bash
88-
npm install --dev @types/web3.js
89-
```
90-
91-
You might need to install type definitions for `bignumber.js` and `lodash` too.
83+
We support types within the repo itself. Please open an issue here if you find any wrong types.
9284

93-
And then use `web3.js` as follows:
85+
You can use `web3.js` as follows:
9486

9587
```typescript
96-
import Web3 = require("web3"); // Note the special syntax! Copy this line when in doubt!
97-
const web3 = new Web3("ws://localhost:8546");
88+
import Web3 from 'web3';
89+
const web3 = new Web3('ws://localhost:8546');
9890
```
9991

100-
**Please note:** We do not support TypeScript ourselves. If you have any issue with TypeScript and `web3.js` do not create an issue here. Go over to DefinitelyTyped and do it there.
92+
If you are using the types in a `commonjs` module like for example a node app you just have to enable `esModuleInterop` in your `tsconfig` compile option, also enable `allowSyntheticDefaultImports` for typesystem compatibility:
93+
94+
```js
95+
"compilerOptions": {
96+
"allowSyntheticDefaultImports": true,
97+
"esModuleInterop": true,
98+
....
99+
```
101100
102101
## Documentation
103102
104103
Documentation can be found at [read the docs][docs].
105104
106-
107105
## Building
108106
109107
### Requirements
110108
111-
* [Node.js](https://nodejs.org)
112-
* [npm](https://www.npmjs.com/)
109+
- [Node.js](https://nodejs.org)
110+
- [npm](https://www.npmjs.com/)
113111
114112
```bash
115113
sudo apt-get update
@@ -133,7 +131,6 @@ npm run-script build-all
133131
134132
This will put all the browser build files into the `dist` folder.
135133
136-
137134
### Testing (mocha)
138135
139136
```bash
@@ -142,22 +139,22 @@ npm test
142139
143140
### Contributing
144141
145-
- All contributions have to go into develop, or the 1.0 branch
146-
- Please follow the code style of the other files, we use 4 spaces as tabs.
142+
- All contributions have to go into develop, or the 1.0 branch
143+
- Please follow the code style of the other files, we use 4 spaces as tabs.
147144
148145
### Community
149-
- [Gitter](https://gitter.im/ethereum/web3.js?source=orgpage)
150-
- [Forum](https://forum.ethereum.org/categories/ethereum-js)
151146
147+
- [Gitter](https://gitter.im/ethereum/web3.js?source=orgpage)
148+
- [Forum](https://forum.ethereum.org/categories/ethereum-js)
152149
153150
### Similar libraries in other languages
154-
- Python - [Web3.py](https://github.com/ethereum/web3.py)
155-
- Haskell - [hs-web3](https://github.com/airalab/hs-web3)
156-
- Java - [web3j](https://github.com/web3j/web3j)
157-
- Scala - [web3j-scala](https://github.com/mslinn/web3j-scala)
158-
- Purescript - [purescript-web3](https://github.com/f-o-a-m/purescript-web3)
159-
- PHP - [web3.php](https://github.com/sc0Vu/web3.php)
160151
152+
- Python - [Web3.py](https://github.com/ethereum/web3.py)
153+
- Haskell - [hs-web3](https://github.com/airalab/hs-web3)
154+
- Java - [web3j](https://github.com/web3j/web3j)
155+
- Scala - [web3j-scala](https://github.com/mslinn/web3j-scala)
156+
- Purescript - [purescript-web3](https://github.com/f-o-a-m/purescript-web3)
157+
- PHP - [web3.php](https://github.com/sc0Vu/web3.php)
161158
162159
[repo]: https://github.com/ethereum/web3.js
163160
[docs]: http://web3js.readthedocs.io/

docs/web3-eth-personal.rst

Lines changed: 168 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,54 @@ Example
239239
240240
------------------------------------------------------------------------------
241241

242+
sendTransaction
243+
=====================
244+
245+
.. code-block:: javascript
246+
247+
web3.eth.personal.sendTransaction(transactionOptions, password [, callback])
248+
249+
This method sends a transaction over the management API.
250+
251+
.. note:: Sending your account password over an unsecured HTTP RPC connection is highly unsecure.
252+
253+
----------
254+
Parameters
255+
----------
256+
257+
258+
1. ``Object`` - The transaction options
259+
2. ``String`` - The passphrase for the current account
260+
3. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.
261+
262+
263+
-------
264+
Returns
265+
-------
266+
267+
268+
``Promise<string>`` - The transaction hash.
269+
270+
271+
-------
272+
Example
273+
-------
274+
275+
276+
.. code-block:: javascript
277+
278+
web3.eth.sendTransaction({
279+
from: "0xEB014f8c8B418Db6b45774c326A0E64C78914dC0",
280+
gasPrice: "20000000000",
281+
gas: "21000",
282+
to: '0x3535353535353535353535353535353535353535',
283+
value: "1000000000000000000",
284+
data: ""
285+
}, 'MyPassword!').then(console.log);
286+
> '0xda3be87732110de6c1354c83770aae630ede9ac308d9f7b399ecfba23d923384'
287+
288+
------------------------------------------------------------------------------
289+
242290

243291
unlockAccount
244292
=====================
@@ -271,6 +319,124 @@ Example
271319
.then(console.log('Account unlocked!'));
272320
> "Account unlocked!"
273321
274-
// TODO
322+
------------------------------------------------------------------------------
323+
324+
lockAccount
325+
=====================
326+
327+
.. code-block:: javascript
328+
329+
web3.eth.personal.lockAccount(address [, callback])
330+
331+
Locks the given account.
332+
333+
.. note:: Sending your account password over an unsecured HTTP RPC connection is highly unsecure.
334+
335+
----------
336+
Parameters
337+
----------
338+
339+
340+
1. ``address`` - ``String``: The account address.
341+
4. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.
342+
343+
344+
-------
345+
Returns
346+
-------
347+
348+
349+
``Promise<boolean>``
350+
351+
352+
-------
353+
Example
354+
-------
355+
356+
357+
.. code-block:: javascript
358+
359+
web3.eth.personal.lockAccount("0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe")
360+
.then(console.log('Account locked!'));
361+
> "Account locked!"
362+
363+
------------------------------------------------------------------------------
364+
365+
.. _personal-getaccounts:
366+
367+
getAccounts
368+
=====================
369+
370+
.. code-block:: javascript
371+
372+
web3.eth.personal.getAccounts([callback])
373+
374+
Returns a list of accounts the node controls by using the provider and calling
375+
the RPC method ``personal_listAccounts``. Using :ref:`web3.eth.accounts.create() <accounts-create>`
376+
will not add accounts into this list. For that use
377+
:ref:`web3.eth.personal.newAccount() <personal-newaccount>`.
378+
379+
The results are the same as :ref:`web3.eth.getAccounts() <eth-getaccounts>` except that calls
380+
the RPC method ``eth_accounts``.
381+
382+
-------
383+
Returns
384+
-------
385+
386+
387+
``Promise<Array>`` - An array of addresses controlled by node.
388+
389+
-------
390+
Example
391+
-------
392+
393+
394+
.. code-block:: javascript
395+
396+
web3.eth.personal.getAccounts()
397+
.then(console.log);
398+
> ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf"]
399+
400+
------------------------------------------------------------------------------
401+
402+
importRawKey
403+
=====================
404+
405+
.. code-block:: javascript
406+
407+
web3.eth.personal.importRawKey(privateKey, password)
408+
409+
Imports the given private key into the key store, encrypting it with the passphrase.
410+
411+
Returns the address of the new account.
412+
413+
.. note:: Sending your account password over an unsecured HTTP RPC connection is highly unsecure.
414+
415+
----------
416+
Parameters
417+
----------
418+
419+
420+
1. ``privateKey`` - ``String`` - An unencrypted private key (hex string).
421+
2. ``password`` - ``String`` - The password of the account.
422+
423+
424+
-------
425+
Returns
426+
-------
427+
428+
429+
``Promise<string>`` - The address of the account.
430+
431+
-------
432+
Example
433+
-------
434+
435+
436+
.. code-block:: javascript
437+
438+
web3.eth.personal.importRawKey("cd3376bb711cb332ee3fb2ca04c6a8b9f70c316fcdf7a1f44ef4c7999483295e", "password1234")
439+
.then(console.log);
440+
> "0x8f337bf484b2fc75e4b0436645dcc226ee2ac531"
441+
275442
276-
getAccounts, lockAccount, sendTransaction

docs/web3-eth.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,3 +1558,30 @@ Example
15581558
> 61
15591559
15601560
------------------------------------------------------------------------------
1561+
1562+
.. _eth-getNodeInfo:
1563+
1564+
getNodeInfo
1565+
===========
1566+
1567+
.. code-block:: javascript
1568+
1569+
web3.eth.getNodeInfo([callback])
1570+
1571+
-------
1572+
Returns
1573+
-------
1574+
1575+
``Promise<String>`` - The current client version.
1576+
1577+
-------
1578+
Example
1579+
-------
1580+
1581+
1582+
.. code-block:: javascript
1583+
1584+
web3.eth.getNodeInfo().then(console.log);
1585+
> "Mist/v0.9.3/darwin/go1.4.1"
1586+
1587+
------------------------------------------------------------------------------

0 commit comments

Comments
 (0)