Skip to content
SpartanCoin - spartancoin.tiv.cc

Using SPNCXX to write SpartanCoin Blockchain Based Application

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 Library Fossil Project

Now let's begin coding!

SpartanCoin Xjail 320p
SpartanCoin Xjail 320p

Include Headers.

#include <spncxx/client.hxx>

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

auto conn = spn::connection("127.0.0.1", "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("127.0.0.1", "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;
    }
}

Build:

$ 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

 

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
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.
CAPTCHA

Form options

Submitted comments will be subject to moderation before being displayed.