Casper C++ SDK provides an interface to establish a connection between the Casper Blockchain and a client.
- CMake Version 3.0.0 or newer
- Doxygen Version 1.8.8 or newer
- OpenSSL Version 1.1.1 or newer
- cryptopp Version 8.6.0 or newer
sudo apt update
sudo apt install build-essential cmake libssl-dev graphviz doxygen ninja-build libspdlog-dev
git clone https://github.com/gabime/spdlog.git
cd spdlog && mkdir build && cd build
cmake -DCMAKE_CXX_FLAGS=-fPIC .. && make -j && sudo make install
or via package manager:
sudo dnf install spdlog-devel
On CentOS and Rocky Linux:
sudo dnf config-manager --set-enabled powertools
sudo dnf install doxygen
Can be used for Windows, Linux and MacOS (fix your paths in the examples)
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
git checkout 2022.08.15
./bootstrap-vcpkg.sh
sudo apt-get install pkg-config
sudo dnf update && sudo dnf upgrade
sudo reboot
sudo dnf install kernel-headers kernel-devel autoconf-archive mesa-libGLU-devel R 'xcb-util-*-devel' libxkbcommon-x11-devel libxkbcommon-devel
sudo yum install perl-IPC-Cmd
windows:
vcpkg install @mydir\casper-cpp-sdk\vcpkg\vcpkg.txt --triplet=x64-windows --clean-after-build
linux:
./vcpkg install boost-algorithm boost-property-tree boost-variant cryptopp openssl spdlog --triplet=x64-linux --clean-after-build
macos:
./vcpkg install @mydir/casper-cpp-sdk/vcpkg/vcpkg.txt --triplet=x64-osx --clean-after-build
windows:
vcpkg export @mydir\casper-cpp-sdk\vcpkg\vcpkg.txt --raw --triplet=x64-windows --output-dir=mydir\vcpkg-bin-win-casper-cpp-sdk --output=01
linux:
./vcpkg export boost-algorithm boost-property-tree boost-variant cryptopp openssl spdlog --raw --triplet=x64-linux --output-dir=mydir/vcpkg-bin-lin-casper-cpp-sdk --output=01
./vcpkg export @mydir/casper-cpp-sdk/vcpkg/vcpkg.txt --raw --triplet=x64-linux --output-dir=mydir/vcpkg-bin-lin-casper-cpp-sdk --output=01
or an alternative way if above doesn't work:
./vcpkg export <list of packages from vcpkg.txt seperated by space> --raw --triplet=x64-linux --output-dir=/mydir/vcpkg-bin-lin-casper-cpp-sdk --output=01
macos:
./vcpkg export @mydir/casper-cpp-sdk/vcpkg/vcpkg.txt --raw --triplet=x64-osx --output-dir=mydir/vcpkg-bin-mac-casper-cpp-sdk --output=01
Using deps from system (linux only, need to install additional dependencies)
mkdir build && cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug ..
ninja
Using deps from vcpkg (Linux, Windows, macOS)(Suggested)
mkdir build && cd build
windows:
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=mydir/vcpkg-bin-win-casper-cpp-sdk/01/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows ..
linux:
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=mydir/vcpkg-bin-lin-casper-cpp-sdk/01/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-linux ..
macos:
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=mydir/vcpkg-bin-mac-casper-cpp-sdk/01/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-osx ..
cmake --build .
Using deps from system (linux only)
mkdir build && cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
ninja
Using deps from system (linux only)
mkdir build && cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCASPER_SDK_TESTS=ON ..
ninja
./test/casper_cpp_sdk_tests
mkdir build && cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCASPER_SDK_EXAMPLES=ON ..
ninja
./examples/example
mkdir build && cd build
cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
ninja
sudo ninja install
1. Include the header file to the application file.
#include "CasperClient.h"
2. Link the installed SDK to the application. A CMake example is given below.
add_executable(ApplicationName main.cpp)
target_link_libraries(ApplicationName PUBLIC CasperSDK)
Usage of the RPC functions are described in the examples/HelloSDK.cpp file.
1. Define a CasperClient object and connect to the Casper Blockchain. Replace the IP address and port number to the IP address and port number of any Casper Blockchain node.
Casper::Client client("http://127.0.0.1:7777");
2. Call the client object member functions listed with their return types below to perform RPC functions.
Client Function | Return Type |
---|---|
GetNodePeers | Casper::InfoGetPeersResult |
GetStateRootHash | Casper::GetStateRootHashResult |
GetDeployInfo | Casper::GetDeployInfoResult |
GetStatusInfo | Casper::GetStatusResult |
GetBlockTransfers | Casper::GetBlockTransfersResult |
GetBlock | Casper::GetBlockResult |
GetEraInfoBySwitchBlock | Casper::GetEraInfoResult |
GetItem | Casper::GetItemResult |
GetDictionaryItem | Casper::GetDictionaryItemResult |
GetAccountBalance | Casper::GetBalanceResult |
GetAuctionInfo | Casper::GetAuctionInfoResult |
PutDeploy | Casper::PutDeployResult |
cd docs
doxygen Doxyfile
The documentation will be available in the "docs/html/index.html" file.
- https://github.com/nlohmann/json
- https://github.com/jsonrpcx/json-rpc-cxx
- https://github.com/yhirose/cpp-httplib
- https://github.com/weidai11/cryptopp
- https://github.com/Neargye/magic_enum
- https://github.com/codeinred/recursive-variant
- https://github.com/ckormanyos/wide-integer
- https://github.com/mity/acutest