If you are developing a service on Obyte and your programming language is node.js, your best option is to just require() the ocore modules that you need.
For exchanges and other custody wallets, there is a specialized JSON RPC service. However it is limited and exposes only those functions that the exchanges need.
If you are developing a service on Obyte and your programming language is node.js, your best option is to just require() the ocore modules that you need (most likely you need headless-obyte and various modules inside ocore). This way, you'll also be running a Obyte node in-process.
If you are programming in another language, or you'd like to run your Obyte node in a separate process, you can still access many of the functions of headless-obyte and ocoreby creating a thin RPC wrapper around the required functions and then calling them via JSON-RPC.
Get started
To get started, we can add RPCify to existing project or directly to headless-obyte with this command:
npminstallhttps://github.com/byteball/rpcify.git
See the documentation about RPCify for more details.
Exposing functions and events
To expose the required functions via JSON-RPC, create a project that has headless-obyte, ocore (and any other ocore modules) and RPCify as dependencies:
var rpcify =require('rpcify');var eventBus =require('ocore/event_bus.js');// this is a module whose methods you want to expose via RPCvar headlessWallet =require('headless-obyte'); // when headless-obyte is dependency of your project//var headlessWallet = require('../start.js'); // when this script is in headless-obyte tools foldervar balances =require('ocore/balances.js'); // another such module// most of these functions become available only after the passphrase is enteredeventBus.once('headless_wallet_ready',function(){// start listening on RPC portrpcify.listen(6333,'127.0.0.1');// expose some functions via RPCrpcify.expose(headlessWallet.issueChangeAddressAndSendPayment);rpcify.expose(balances.readBalance,true);rpcify.expose(balances.readAllUnspentOutputs);rpcify.expose([headlessWallet.readFirstAddress,headlessWallet.readSingleWallet,headlessWallet.issueOrSelectAddressByIndex ],true);// expose some events rpcify.exposeEvent(eventBus,"my_transactions_became_stable");rpcify.exposeEvent(eventBus,"new_my_transactions");});
Calling with HTTP requests
From another Node.js app, calling the function would look something like this: