Modified from ethereum:web3.js 0.20.0
var Chain3 = require('chain3');
var chain3 = new Chain3();
This is the MOAC compatible JavaScript API which implements the Generic JSON RPC spec as described in the Chain3.md. It's available on npm as a node module, for bower and component as an embeddable js and as a meteor.js package.
Some of the methods require running a local MOAC node to use this library.
npm install chain3
Bower
bower install chain3
Component
component install moac/chain3.js
- Include
chain3.min.js
in your html file. (not required for the meteor package)
Use the chain3
object directly from global namespace:
console.log(chain3); // {mc: .., db: ..., net: ...} // it's here!
Set a provider (HttpProvider)
if (typeof chain3 !== 'undefined') {
chain3 = new Chain3(chain3.currentProvider);
} else {
// set the provider you want from Chain3.providers
chain3 = new Chain3(new Chain3.providers.HttpProvider("http://localhost:8545"));
}
Set a provider (HttpProvider using HTTP Basic Authentication)
chain3.setProvider(new chain3.providers.HttpProvider('http://host.url', 0, BasicAuthUsername, BasicAuthPassword));
There you go, now you can use it:
var coinbase = chain3.mc.coinbase;
var balance = chain3.mc.getBalance(coinbase);
More examples are under the example directory
- Node.js
- npm
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
sudo apt-get install nodejs-legacy
Require install gulp (https://gulpjs.com/) in the system:
npm run-script build
Test all cases.
npm test
Test a singe function.
mocha test/chain3.mc.coinbase.js
The server directory contains the example codes to build a web server to access the MOAC network using this API library.
browserify-cryptojs v0.3.1