Skip to content

Commit

Permalink
Types back-port from 2.x with changes to match the 1.x logic (web3#3132)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
joshstevens19 authored and nachomazzara committed Jun 4, 2020
1 parent 678ba2d commit af89325
Show file tree
Hide file tree
Showing 185 changed files with 15,179 additions and 2,145 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ bower_components
.vscode/
dist/
packages/web3/dist/
lerna-debug.log
!./dist/web3.min.js
57 changes: 27 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
This is the Ethereum [JavaScript API][docs]
which connects to the [Generic JSON RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC) spec.


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

Please read the [documentation][docs] for more.
Expand All @@ -38,15 +37,15 @@ yarn add web3

### Meteor

*Note*: works only in the Browser for now. (PR welcome).
_Note_: works only in the Browser for now. (PR welcome).

```bash
meteor add ethereum:web3
```

### In the Browser

Use the prebuild ``dist/web3.min.js``, or
Use the prebuild `dist/web3.min.js`, or
build using the [web3.js][repo] repository:

```bash
Expand Down Expand Up @@ -83,40 +82,39 @@ web3.setProvider(new Web3.providers.WebsocketProvider('ws://localhost:8546'));
There you go, now you can use it:

```js
web3.eth.getAccounts()
.then(console.log);
web3.eth.getAccounts().then(console.log);
```

### Usage with TypeScript

Type definitions are maintained at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) by others. You can install them with:

```bash
npm install --dev @types/web3.js
```

You might need to install type definitions for `bignumber.js` and `lodash` too.
We support types within the repo itself. Please open an issue here if you find any wrong types.

And then use `web3.js` as follows:
You can use `web3.js` as follows:

```typescript
import Web3 = require("web3"); // Note the special syntax! Copy this line when in doubt!
const web3 = new Web3("ws://localhost:8546");
import Web3 from 'web3';
const web3 = new Web3('ws://localhost:8546');
```

**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.
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:

```js
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
....
```
## Documentation
Documentation can be found at [read the docs][docs].

## Building
### Requirements
* [Node.js](https://nodejs.org)
* [npm](https://www.npmjs.com/)
- [Node.js](https://nodejs.org)
- [npm](https://www.npmjs.com/)
```bash
sudo apt-get update
Expand All @@ -140,7 +138,6 @@ npm run-script build-all
This will put all the browser build files into the `dist` folder.

### Testing (mocha)
```bash
Expand All @@ -149,22 +146,22 @@ npm test
### Contributing
- All contributions have to go into develop, or the 1.0 branch
- Please follow the code style of the other files, we use 4 spaces as tabs.
- All contributions have to go into develop, or the 1.0 branch
- Please follow the code style of the other files, we use 4 spaces as tabs.
### Community
- [Gitter](https://gitter.im/ethereum/web3.js?source=orgpage)
- [Forum](https://forum.ethereum.org/categories/ethereum-js)
- [Gitter](https://gitter.im/ethereum/web3.js?source=orgpage)
- [Forum](https://forum.ethereum.org/categories/ethereum-js)
### Similar libraries in other languages
- Python - [Web3.py](https://github.com/ethereum/web3.py)
- Haskell - [hs-web3](https://github.com/airalab/hs-web3)
- Java - [web3j](https://github.com/web3j/web3j)
- Scala - [web3j-scala](https://github.com/mslinn/web3j-scala)
- Purescript - [purescript-web3](https://github.com/f-o-a-m/purescript-web3)
- PHP - [web3.php](https://github.com/sc0Vu/web3.php)
- Python - [Web3.py](https://github.com/ethereum/web3.py)
- Haskell - [hs-web3](https://github.com/airalab/hs-web3)
- Java - [web3j](https://github.com/web3j/web3j)
- Scala - [web3j-scala](https://github.com/mslinn/web3j-scala)
- Purescript - [purescript-web3](https://github.com/f-o-a-m/purescript-web3)
- PHP - [web3.php](https://github.com/sc0Vu/web3.php)
[repo]: https://github.com/ethereum/web3.js
[docs]: http://web3js.readthedocs.io/
Expand Down
170 changes: 168 additions & 2 deletions docs/web3-eth-personal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,54 @@ Example
------------------------------------------------------------------------------

sendTransaction
=====================

.. code-block:: javascript
web3.eth.personal.sendTransaction(transactionOptions, password [, callback])
This method sends a transaction over the management API.

.. note:: Sending your account password over an unsecured HTTP RPC connection is highly unsecure.

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


1. ``Object`` - The transaction options
2. ``String`` - The passphrase for the current account
3. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.


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


``Promise<string>`` - The transaction hash.


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


.. code-block:: javascript
web3.eth.sendTransaction({
from: "0xEB014f8c8B418Db6b45774c326A0E64C78914dC0",
gasPrice: "20000000000",
gas: "21000",
to: '0x3535353535353535353535353535353535353535',
value: "1000000000000000000",
data: ""
}, 'MyPassword!').then(console.log);
> '0xda3be87732110de6c1354c83770aae630ede9ac308d9f7b399ecfba23d923384'
------------------------------------------------------------------------------


unlockAccount
=====================
Expand Down Expand Up @@ -271,6 +319,124 @@ Example
.then(console.log('Account unlocked!'));
> "Account unlocked!"
// TODO
------------------------------------------------------------------------------

lockAccount
=====================

.. code-block:: javascript
web3.eth.personal.lockAccount(address [, callback])
Locks the given account.

.. note:: Sending your account password over an unsecured HTTP RPC connection is highly unsecure.

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


1. ``address`` - ``String``: The account address.
4. ``Function`` - (optional) Optional callback, returns an error object as first parameter and the result as second.


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


``Promise<boolean>``


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


.. code-block:: javascript
web3.eth.personal.lockAccount("0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe")
.then(console.log('Account locked!'));
> "Account locked!"
------------------------------------------------------------------------------

.. _personal-getaccounts:

getAccounts
=====================

.. code-block:: javascript
web3.eth.personal.getAccounts([callback])
Returns a list of accounts the node controls by using the provider and calling
the RPC method ``personal_listAccounts``. Using :ref:`web3.eth.accounts.create() <accounts-create>`
will not add accounts into this list. For that use
:ref:`web3.eth.personal.newAccount() <personal-newaccount>`.

The results are the same as :ref:`web3.eth.getAccounts() <eth-getaccounts>` except that calls
the RPC method ``eth_accounts``.

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


``Promise<Array>`` - An array of addresses controlled by node.

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


.. code-block:: javascript
web3.eth.personal.getAccounts()
.then(console.log);
> ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf"]
------------------------------------------------------------------------------

importRawKey
=====================

.. code-block:: javascript
web3.eth.personal.importRawKey(privateKey, password)
Imports the given private key into the key store, encrypting it with the passphrase.

Returns the address of the new account.

.. note:: Sending your account password over an unsecured HTTP RPC connection is highly unsecure.

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


1. ``privateKey`` - ``String`` - An unencrypted private key (hex string).
2. ``password`` - ``String`` - The password of the account.


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


``Promise<string>`` - The address of the account.

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


.. code-block:: javascript
web3.eth.personal.importRawKey("cd3376bb711cb332ee3fb2ca04c6a8b9f70c316fcdf7a1f44ef4c7999483295e", "password1234")
.then(console.log);
> "0x8f337bf484b2fc75e4b0436645dcc226ee2ac531"
getAccounts, lockAccount, sendTransaction
27 changes: 27 additions & 0 deletions docs/web3-eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1558,3 +1558,30 @@ Example
> 61
------------------------------------------------------------------------------

.. _eth-getNodeInfo:

getNodeInfo
===========

.. code-block:: javascript
web3.eth.getNodeInfo([callback])
-------
Returns
-------

``Promise<String>`` - The current client version.

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


.. code-block:: javascript
web3.eth.getNodeInfo().then(console.log);
> "Mist/v0.9.3/darwin/go1.4.1"
------------------------------------------------------------------------------
Loading

0 comments on commit af89325

Please sign in to comment.