You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
moneroexamples 6e0c9e4b9f
Merge branch 'master' of
4 years ago
cmake make it compile with latest monero 4 years ago
ext updated json.hpp 5 years ago
src Merge branch 'master' of 4 years ago
tests changed multimap to map 4 years ago
.gitignore mocks.h updated 5 years ago
.gitmodules first commit 5 years ago
CMakeLists.txt exmaple.cpp and README updated 5 years ago
LICENSE Update LICENSE 5 years ago new make_primaryaccount added 5 years ago
example.cpp new make_primaryaccount added 5 years ago

Core repository of moneroexamples

This repository includes code that is oftenly used among moneroexamples projects. It includes:

  • classess for decoding outputs/inputs, payment ids,
  • general utility tools (e.g., get default monero blockchain path),
  • unified representation of monero addresses/accounts,
  • identification of outputs for subaddresses based on primary address,
  • estimation of possible spendings based on address and viewkey.

Example usage

More examples along with its full code are located in example.cpp.

Identify outputs in a tx based on address and viewkey with subaddresses

// use Monero forum donation address and viewkwey.
// will search for outputs in a give tx to
// to the primary address and its subaddresses. 
auto primary_account = xmreg::make_primaryaccount(

auto tx = get_tx("54cef43983ca9eeded46c6cc1091bf6f689d91faf78e306a5ac6169e981105d8");

// so now we can create an instance of a universal identifier
// which is going to identify outputs in a given tx using
// address and viewkey data. the search will include subaddresses.
auto identifier = make_identifier(*tx,


// get the results of the identification
auto outputs_found = identifier.get<xmreg::Output>()->get();

cout << "Found following outputs in tx " << tx << ":\n"
     << outputs_found << '\n';

Identified output for 0.081774999238 xmr is for a subaddress of index 0/10 which in this case is for the "xiphon part time coding (3 months)" proposal.

Possible spending based on address and viewkey

// use offical Monero project donation address and viewkwey.
// will search for outputs and inputs in a give tx addressed 
// to the primary address only. this search will not account
// for any outputs sent to subaddresses.
auto account = xmreg::make_account(

auto tx = get_tx("aa739a3ce8d3171a422ed3a3f5016384cdb17a5d3eb5905021f1103574d47eaf");

// we can join individual identifiers as shown below, since to estimate
// spendings we need to identify possible inputs with their amount values,
// as well as outputs corresponding to the change returned to Monero
// donation address
auto identifier = make_identifier(*tx,
      make_unique<xmreg::GuessInput>(account.get(), &mcore));


// get identified outputs and inputs in the tx
auto outputs_found = identifier.get<xmreg::Output>()->get();
auto inputs_found = identifier.get<xmreg::GuessInput>()->get();

// possible spending is just basic math
auto possible_total_spent = xmreg::calc_total_xmr(inputs_found)
                            - xmreg::calc_total_xmr(outputs_found)
                            - get_tx_fee(*tx);

cout << "Possible spending from Monero project donation is: " 
     << print_money(possible_total_spent) << " xmr\n";

Result is 118.778154000000 xmr which possibly were withdrawn from Monero donation address.

Identify and decrypt integrated payment id

// use Monero forum donation address and viewkwey
auto account = xmreg::make_account(

auto tx = get_tx("401bf77c9a49dd28df5f9fb15846f9de05fce5f0e11da16d980c4c9ac9156354");

auto identifier = make_identifier(*tx,


auto payment_id = identifier.get<xmreg::IntegratedPaymentID>()->get();

cout << "Found following itegrated payment id in tx " << payment_id << '\n';

The result is decrypted short payment id of 1fcbb836a748f4dc. The tx is also a possible withdrawn from Monero forum donation wallet for 350 xmr (see examples.cpp for the code).


The project depends on monero libraries and it has same dependecies as the monero
(except C++14 requirement). Thus monero needs to be setup first.

Monero download and compilation

Follow instructions in the following link:

Compilation of the xmregcore

C++14 is required to compile the project. This means that GCC 7.1 or higher can be used. For example, Ubuntu 18.04 ships with GCC 7.3 which is sufficient.

# go to home folder if still in ~/monero
cd ~

git clone --recurse-submodules

cd xmregcore

mkdir build && cd build

cmake ..

# alternatively can use cmake -DMONERO_DIR=/path/to/monero_folder ..
# if monero is not in ~/monero


# run tests
make test

Other examples

Other examples can be found on github. Please know that some of the examples/repositories are not finished and may not work as intended.

How can you help?

Constructive criticism and code are always welcomed. They can be made through github.