bitwala
v0.0.3
Published
Node client for the Bitwala API (docs.bitwala.apiary.io)
Downloads
6
Readme
API Node Client
Node client for the Bitwala.
For a detailed explanation of our API routes, please check out the documentation
Quick Start
- Go to https://my.bitwala.io/api-apps
- Create an app and store your token ID and secret
yarn add bitwala
import bitwala from 'bitwala';
const token = {
_id: 'SuBnyc6d564P49Uuls',
secret: 'LTdFE6hw725yh0aM4m4azACEZSpNrtl4aowFjCZetSAAPBaGN3Ecq7FgMSR5b3Va'
};
const client = bitwala.client({
token: token,
env: 'sandbox'
});
client.info('inputs')
.then(data => console.log(data))
.catch(err => console.error(err));
/*
[
{
"collection": "BitcoinInvoices",
"currency": "XBT"
}
]
*/
Environments
The client can be initialised with the sandbox
or production
env.
For a breakdown of the differences, see our docs.
Methods
| Endpoint | Method | Client |
|-----------------|--------|-------------------|
| /info
| GET | .info()
|
| /info/inputs
| GET | .info('inputs')
|
| /info/outputs
| GET | .info('outputs')
|
| /auth
| GET | .auth()
|
| /transactions?page=1
| GET | .transactions.get({page: 1})
|
| /transactions?transactionId=transactionId
| GET | .transactions.get({transactionId: 'YRTvEJxAEm3MB1GI'})
|
| /transactions?ref=ref
| GET | .transactions.get({ref: 'YRTvEJxAEm3MB1GI'})
|
| /transactions
| POST | .transactions.create(yourTransactionObj})
|
| /transactions/refresh
| POST | .transactions.refresh({transactionId: transactionId}})
|
| /transactions/refresh
| POST | .transactions.refresh({transactionId: transactionId}})
|
Promises / Callbacks
All api calls can be used with promises or callbacks.
With callbacks
client.info((e, data) => {
if (e) {
return console.error(e);
}
console.log(data);
})
With promises
client.info()
.then(data => console.log(data));
With await
and async
(if you're using ES7)
(async function () {
let data;
try {
await data = client.info();
} catch (err) {
console.error(err);
}
console.log(data);
})();
Examples
Get a transaction by ref
client.transactions.get({ref: 'My custom id'});
.then(r => console.log(r))
.catch(err => console.log(err));
Create a transfer to Germany
client.transactions.create({
ref: 'My custom id',
webhookUrl: '...', // example: https://test.com/callbacks/bitwala
inputs: [{
collection: 'BitcoinInvoices',
doc: {
currency: 'XBT',
convertedCurrency: 'EUR',
convertedAmount: 100
}
}],
outputs: [{
collection: 'BankTransfers',
doc: {
amount: 100,
currency: 'EUR',
reference: 'January Salary',
bankAccount: {
recipientType: 'INDIVIDUAL',
firstName: 'Satoshi',
lastName: 'Nakamoto',
iban: 'DE89370400440532013000',
currency: 'EUR'
}
}
}]
}).then(r => console.log(r))
.catch(err => console.log(err));
Receive and verify webhooks
import bitwala from 'bitwala';
import express from 'express';
import bodyParser from 'body-parser';
const token = {
_id: 'SuBnyc6d564P49Uuls',
secret: 'LTdFE6hw725yh0aM4m4azACEZSpNrtl4aowFjCZetSAAPBaGN3Ecq7FgMSR5b3Va'
};
const router = express.Router();
router.use(bodyParser.json({
limit: '100kb',
type: 'application/*+json'
}));
router.post('/callbacks/bitwala', function (req, res, next) {
// !important: use body-parser
const signatureOk = bitwala.verifications.verifyCallback(req, token.secret);
...
res.success();
});
...