@hyperdapp/web4
v0.20.7
Published
Theos & Hyperdapp JavaScript API, middleware to talk to a theos node over RPC
Downloads
37
Maintainers
Readme
Hyperdapp & Theos JavaScript API
This is the Ethereum compatible JavaScript API which implements the Generic JSON RPC spec. It's available on npm as a node module, for Bower and component as embeddable scripts, and as a meteor.js package.
You need to run a local Ethereum node to use this library.
Table of Contents
Installation
Node.js
npm install web4
Yarn
yarn add web4
Meteor.js
meteor add hyperdapp:web4
As a Browser module
CDN
<script src="https://cdn.jsdelivr.net/gh/hyperdapp/[email protected]/dist/web4.min.js" integrity="sha256-nWBTbvxhJgjslRyuAKJHK+XcZPlCnmIAAMixz6EefVk=" crossorigin="anonymous"></script>
Bower
bower install web4
Component
component install hyperdapp/web4.js
- Include
web4.min.js
in your html file. (not required for the meteor package)
Usage
Use the web4
object directly from the global namespace:
console.log(web4); // {eth: .., shh: ...} // It's here!
Set a provider (HttpProvider
):
if (typeof web4 !== 'undefined') {
web4 = new web4(web4.currentProvider);
} else {
// Set the provider you want from web4.providers
web4 = new web4(new web4.providers.HttpProvider("http://localhost:8545"));
}
Set a provider (HttpProvider
using HTTP Basic Authentication):
web4.setProvider(new web4.providers.HttpProvider('http://' + BasicAuthUsername + ':' + BasicAuthPassword + '@localhost:8545'));
There you go, now you can use it:
var coinbase = web4.eth.coinbase;
var balance = web4.eth.getBalance(coinbase);
You can find more examples in the example
directory.
Migration from 0.13.0 to 0.14.0
web4.js version 0.14.0 supports multiple instances of the web4 object. To migrate to this version, please follow the guide:
-var web4 = require('web4');
+var web4 = require('web4');
+var web4 = new web4();
Contribute!
Requirements
- Node.js
- npm
# On Linux:
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
sudo apt-get install nodejs-legacy
Building (gulp)
npm run-script build
Testing (mocha)
npm test
Community
Other upcoming implementations
- Python web4.py
License
MIT © 2018 Contributors
LGPL-3.0+ © 2015 Contributors For any omissions, please contact us at [email protected]