Skip to content

Using SPNCXX to Write SpartanCoin Applications


C++ SPNCXX is specially written for SpartanCoin JSON-RPC integrating into Application. It is very easy to integrate that.

// 1. include spncxx client header.
#Include <spncxx/client.hxx>

// 2. Create a connection to the SpartanCoin Wallet or blockchain RPC server.
auto conn = spn::connection("", "55883", "rpc-username", "rpc-password");
Notice that spn::connection returns
such a c++ future object: std::future>
You are not suggested to create the spn::Client object directly because
it is not safe.

// 3. Get the spn::Client shared ptr.
auto client = conn.get();
// The get of that future returns std::shared_ptr object.

// 4. Request RPC Command to query blockchain data.
double diff = client->getdifficulty();


Firstly you need to run a SpartanCoin Wallet Application. When you run it you will own an RPC daemon to be being connected.

Download SpartanCoin

Then get and build the spncxx library, which contains lots of tests.

SPNCXX Project

Now let's begin coding!

Include Headers.

#include <spncxx/client.hxx>

Create a connection connecting to the SpartanCoin JSON-RPC Daemon.

auto conn = spn::connection("", "55883", "rpc-username", "rpcpassword");

Get the client shared_ptr object.

auto client = conn.get();

Request RPC Command

double balance = client->getbalance();

Example: How to Get the Circulating Supply of SpartanCoin.

// C++ Source Code: supply.cxx

#include <spncxx/client.hxx>
#include <iostream>
#include <iomanip>

int main() {
    try {
        auto client = spn::connection("", "55883", "username", "password").get();
        const json::Value info = client->gettxoutsetinfo();
        const double circulating_supply = info["total_amount"].asDouble();
        std::cout << "SpartanCoin Current Circulating Suppy is "
            << std::fixed << std::setprecision(8)
            << circulating_supply << " SPN" << std::endl;
    } catch (const std::exception & exc) {
        std::cerr << "caught by main: " << exc.what() << std::endl;


$ alias build='clang++ -std=c++17 -I./include -L./ -lthr -pthread -lspncxx -I/usr/local/include/jsoncpp -L/usr/local/lib -ljsoncpp  -DASIO_STANDALONE -DASIO_NO_DEPRECATED'
$ build supply.cxx -o supply
$ ./supply
SpartanCoin Current Circulating Suppy is 52482712500.00000000 SPN



No Trackbacks


Display comments as Linear | Threaded

No comments

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

Form options

Submitted comments will be subject to moderation before being displayed.