upchain-web3-http-provider
v3.1.6
Published
Downloads
9
Readme
Upchain HttpProvider
Extends the built in HTTP Provider with headers
API: I wrapped the provider in a function, so that you can extend the actual existing provider and not a arbitrary existing one in our repo. If you do not pass in a provider, we got you covered ;)
Example Headers
Node.js
var headers = {
'X-API-KEY': 'foo'
}
// new pass the provider to minimize dependencies
var Provider = require('upchain-web3-http-provider')(web3.providers.HttpProvider);
var provider = new Provider('https://localhost:8545', headers);
// set web3
var web3 = new Web3(provider);
// in a pudding / truffle app, reset your
var contracts = [HumanStandardToken,HumanStandardTokenFactory,Token,TokenTester];
// just collect thge contracts and reset the providers as you do it with pudding
contracts.map(function(contract) {
contract.setProvider(window.web3.currentProvider);
});
Example Username / Password
- You can use username and password as part of the url/uri scheme
- however, passing it as a parameter will base64 encode them and put them in a header. This avoids the url end up in logs, containing a username and password.
var headers = {
}
// new pass the provider to minimize dependencies
var Provider = require('upchain-web3-http-provider')(web3.providers.HttpProvider);
var provider = new Provider(
'https://localhost:8545',
headers,
'username',
'password');
// set web3
var web3 = new Web3(provider);
// ....
Browser
The code runs in the browser as well. It registers itself to a global/window variable: UpchainHttpProvider. We provide releases in the cdn, so you dont have to export files yourself. We tried to keep the ocde framework agnostic, so you can use it with angular, meteorjs and other frameworks. A script tag will do.
<script src="https://cdn.rawgit.com/Upchain/upchain-web3-http-provider/v3.1.2/dist/bundle.js" ></script>
Create a provider
var headers = {
'X-API-KEY': 'foo'
};
var Provider = window.UpchainHttpProvider(web3.providers.HttpProvider);
var provider = Provider('https://localhost:8545', headers);
// ....
Release
npm version minor
- pushes to master
- pushes tags
Test
Mocha tests are run.
npm test
Bundle
Bundles all dependencies and writes a usable file using browserify. The file uses window.
npm run bundle