2015-10-19 05:22:16 +00:00
# Migration 0.13.0 -> 0.14.0
web3.js version 0.14.0 supports [multiple instances of web3 ](https://github.com/ethereum/web3.js/issues/297 ) object.
To migrate to this version, please follow the guide:
```diff
-var web3 = require('web3');
+var Web3 = require('web3');
+var web3 = new Web3();
```
2014-09-30 20:55:07 +00:00
# Ethereum JavaScript API
2015-04-20 10:08:42 +00:00
[![Join the chat at https://gitter.im/ethereum/web3.js ](https://badges.gitter.im/Join%20Chat.svg )](https://gitter.im/ethereum/web3.js?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge)
2015-03-22 13:08:22 +00:00
2015-01-26 23:54:21 +00:00
This is the Ethereum compatible [JavaScript API ](https://github.com/ethereum/wiki/wiki/JavaScript-API )
2015-02-27 11:41:07 +00:00
which implements the [Generic JSON RPC ](https://github.com/ethereum/wiki/wiki/JSON-RPC ) spec. It's available on npm as a node module, for bower and component as an embeddable js and as a meteor.js package.
2014-09-30 20:55:07 +00:00
2016-06-29 09:32:43 +00:00
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![dependency status][dep-image]][dep-url] [![dev dependency status][dep-dev-image]][dep-dev-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Stories in Ready][waffle-image]][waffle-url]
2014-11-05 20:33:28 +00:00
2014-11-10 13:26:10 +00:00
<!-- [![browser support ](https://ci.testling.com/ethereum/ethereum.js.png )](https://ci.testling.com/ethereum/ethereum.js) -->
2014-11-05 20:33:28 +00:00
2016-01-05 14:06:29 +00:00
You need to run a local Ethereum node to use this library.
2015-02-27 11:41:07 +00:00
2015-02-27 08:54:39 +00:00
[Documentation ](https://github.com/ethereum/wiki/wiki/JavaScript-API )
2014-11-06 20:51:37 +00:00
## Installation
2014-11-05 17:46:01 +00:00
2014-11-06 20:51:37 +00:00
### Node.js
2014-11-05 17:46:01 +00:00
2015-07-13 13:58:38 +00:00
```bash
npm install web3
```
2015-02-27 08:54:39 +00:00
2017-08-10 12:08:55 +00:00
### Yarn
```bash
yarn add web3
```
2015-02-27 08:54:39 +00:00
### Meteor.js
2015-07-13 13:58:38 +00:00
```bash
meteor add ethereum:web3
```
2014-11-05 17:46:01 +00:00
2015-03-09 09:28:14 +00:00
### As Browser module
2014-11-05 17:46:01 +00:00
Bower
2015-07-13 13:58:38 +00:00
```bash
bower install web3
```
2014-11-05 17:46:01 +00:00
Component
2015-07-13 13:58:38 +00:00
```bash
component install ethereum/web3.js
```
2014-11-05 17:46:01 +00:00
2016-06-27 12:37:18 +00:00
* Include `web3.min.js` in your html file. (not required for the meteor package)
2014-11-05 17:46:01 +00:00
2014-11-06 20:51:37 +00:00
## Usage
2015-04-13 10:15:45 +00:00
Use the `web3` object directly from global namespace:
2015-04-09 22:27:47 +00:00
2015-07-13 13:58:38 +00:00
```js
console.log(web3); // {eth: .., shh: ...} // it's here!
```
2015-04-09 22:27:47 +00:00
2015-07-13 13:55:19 +00:00
Set a provider (HttpProvider)
2014-11-05 17:46:01 +00:00
2015-07-13 13:58:38 +00:00
```js
2017-07-27 13:40:24 +00:00
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
```
Set a provider (HttpProvider using [HTTP Basic Authentication ](https://en.wikipedia.org/wiki/Basic_access_authentication ))
```js
web3.setProvider(new web3.providers.HttpProvider('http://host.url', 0, BasicAuthUsername, BasicAuthPassword));
2015-07-13 13:58:38 +00:00
```
2014-11-05 17:46:01 +00:00
There you go, now you can use it:
2015-07-13 13:58:38 +00:00
```js
2015-01-26 23:54:21 +00:00
var coinbase = web3.eth.coinbase;
2015-02-19 17:37:09 +00:00
var balance = web3.eth.getBalance(coinbase);
2014-11-05 17:46:01 +00:00
```
2015-07-13 13:58:38 +00:00
You can find more examples in [`example` ](https://github.com/ethereum/web3.js/tree/master/example ) directory.
2014-11-05 17:46:01 +00:00
2015-02-27 08:54:39 +00:00
2015-01-11 16:54:36 +00:00
## Contribute!
### Requirements
* Node.js
* npm
```bash
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
sudo apt-get install nodejs-legacy
```
2015-01-15 13:30:34 +00:00
### Building (gulp)
2014-11-05 17:46:01 +00:00
2015-01-15 13:30:34 +00:00
```bash
2015-01-11 16:54:36 +00:00
npm run-script build
```
2014-11-05 17:46:01 +00:00
2015-01-15 13:30:34 +00:00
### Testing (mocha)
2014-09-30 20:55:07 +00:00
2015-01-15 13:30:34 +00:00
```bash
2015-01-11 16:54:36 +00:00
npm test
```
2017-07-27 13:40:24 +00:00
### Community
- [Gitter ](https://gitter.im/ethereum/web3.js?source=orgpage )
- [Forum ](https://forum.ethereum.org/categories/ethereum-js )
### Other implementations
- Python [Web3.py ](https://github.com/pipermerriam/web3.py )
- Haskell [hs-web3 ](https://github.com/airalab/hs-web3 )
- Java [web3j ](https://github.com/web3j/web3j )
2015-04-10 08:07:15 +00:00
[npm-image]: https://badge.fury.io/js/web3.png
[npm-url]: https://npmjs.org/package/web3
[travis-image]: https://travis-ci.org/ethereum/web3.js.svg
[travis-url]: https://travis-ci.org/ethereum/web3.js
[dep-image]: https://david-dm.org/ethereum/web3.js.svg
[dep-url]: https://david-dm.org/ethereum/web3.js
2015-06-10 10:14:44 +00:00
[dep-dev-image]: https://david-dm.org/ethereum/web3.js/dev-status.svg
2015-04-10 08:07:15 +00:00
[dep-dev-url]: https://david-dm.org/ethereum/web3.js#info=devDependencies
[coveralls-image]: https://coveralls.io/repos/ethereum/web3.js/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/r/ethereum/web3.js?branch=master
[waffle-image]: https://badge.waffle.io/ethereum/web3.js.svg?label=ready& title=Ready
2017-06-05 18:33:32 +00:00
[waffle-url]: https://waffle.io/ethereum/web3.js