oxy-ts
v1.0.1
Published
API Wrapper for OXYCoin
Downloads
9
Readme
OXY Javascript Library
Through this library you can interact with a oxy node in an easy way. The library works both in the browser and Node.js.
This library depends on dpos-api-wrapper and it's basically a wrapper of it.
Documentation
The oxy
variable is an instance of DposAPI. You can
read all about it in the jsdoc here.
Quick Start
Include the library in your browser.
Either download dist/browser/index.js
or use unpkgd.com as follows:
<script type="text/javascript" src="https://unpkg.com/oxy-ts/dist/browser/index.js"></script>
<script>
// ...
</script>
Include it with npm (Suitable also for webpack/browserify)
npm i oxy-ts -D
By default this library uses the official OXY node https://wallet.oxycoin.io
but you can use one of your own by
doing so:
var oxy = require('oxy-ts').oxy;
oxy.nodeAddress = 'http://example.com:5566'; // Set your node url here. (no trailing slash)
Compatibility
Browser Support
| | | | | | --- | --- | --- | --- | --- | --- | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 8+ ✔ |
Node support
Node >= 4.x is fully supported :)
Examples
All the APIs are designed to be easy to use. You can use both Callbacks or Promises; you decide.
For example you can open a new account by doing. Be aware that all the methods sending a secret over the network are going to be deprecated:
oxy.accounts.open('secret', function(error, account) {
if (!error) {
// yay!
console.log(account);
} else {
console.log('error: ', error);
}
// ...
});
or
oxy.accounts.open('secret')
.then(function (account) {
console.log(account);
})
.catch(function (error) {
console.log('error: ', error);
});
which can be even shorter if you write your code in TypeScript or ES6
oxy.accounts.open('secret')
.then(console.log)
.catch(error => console.log('error: ', error));
Advanced Usage
In some cases you need to connect to multiple nodes.
To do so, just use the newWrapper method:
var node1 = oxy.newWrapper('http://node1:1234');
var node2 = oxy.newWrapper('http://node2:1234');
// interact with node1 & node2 using the same APIs available within 'oxy' variable.
The library also supports broadcasting client-signed transactions by using the Transport API. You can read more about the Transport (and the others) API at this wiki Page.