Skip to content

Commit

Permalink
Add documentation usage with TypeScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
levino committed Aug 10, 2018
1 parent d0e2219 commit 7d08109
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**PREVIEW RELEASE** This is a beta preview release with breaking changes! The current stable version is 0.20.0
**PREVIEW RELEASE** This is a beta preview release with breaking changes! The current stable version is 0.20.0

<img src="https://github.com/ethereum/web3.js/raw/1.0/web3js.jpg" width=200 />

Expand All @@ -11,7 +11,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 node to use this library.

Please read the [documentation][docs] for more.
Expand All @@ -32,15 +31,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 @@ -69,29 +68,46 @@ console.log(web3);
Additionally you can set a provider using `web3.setProvider()` (e.g. WebsocketProvider)

```js
web3.setProvider('ws://localhost:8546');
web3.setProvider("ws://localhost:8546");
// or
web3.setProvider(new Web3.providers.WebsocketProvider('ws://localhost:8546'));
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.

And then 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");
```

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

## Documentation

Documentation can be found at [read the docs][docs]


## Building

### Requirements

* [Node.js](https://nodejs.org)
* npm
- [Node.js](https://nodejs.org)
- npm

```bash
sudo apt-get update
Expand All @@ -115,7 +131,6 @@ npm run-script build-all

This will put all the browser build files into the `dist` folder.


### Testing (mocha)

```bash
Expand All @@ -124,22 +139,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/pipermerriam/web3.py)
- Haskell [hs-web3](https://github.com/airalab/hs-web3) - Haskell [hs-web3](https://github.com/airalab/hs-web3)
- Java [web3j](https://github.com/web3j/web3j) - 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/pipermerriam/web3.py)
- Haskell [hs-web3](https://github.com/airalab/hs-web3) - Haskell [hs-web3](https://github.com/airalab/hs-web3)
- Java [web3j](https://github.com/web3j/web3j) - 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/en/1.0/
Expand Down

0 comments on commit 7d08109

Please sign in to comment.