Create blockchain video games and applications using the C++ programming language.
Learn more about the Enjin blockchain platform.
Sign up to Enjin Cloud: Kovan (Testnet), Mainnet (Production) or JumpNet.
The Enjin C++ SDK is a C++17 library and is developed with cross-platform usage in mind. Platform and compiler combinations tested are as follows:
- GCC 9.3.0 on Linux (64-bit)
- Clang 10.0.0 on Linux (64-bit)
- MSVC 2019 on Windows 10 (64-bit)
The SDK may be built as a static or shared (dynamic) library. Use the ENJINSDK_BUILD_SHARED
CMake argument to build as
a shared library and set it to "on" (off by default).
The following dependencies are used for building the SDK:
- CMake (3.16+) as a build tool
The following libraries are used by the SDK for some of its functionality and must be locatable by CMake's
find_package()
function, however these libraries are not necessary to link to your own target to use this SDK:
- RapidJSON (1.1.0+) for processing JSON
- spdlog (1.8.0+) for the logger class
- (optional) cpp-httplib (0.8.5+) for a default HTTP client implementation
- openssl (1.1.1) for HTTPS support
- (optional) IXWebSocket (11.0.4+) for a default websocket client implementation
To have the SDK build its default HTTP and websocket clients use the ENJINSDK_BUILD_DEFAULT_HTTP
and
ENJINSDK_BUILD_DEFAULT_WEBSOCKET
as CMake arguments and set them to be "on" (off by default).
To utilize this SDK you may clone it into your project tree with:
$ git clone https://github.com/enjin/Enjin-CPP-SDK.git
Then use the following in your project's CMakeLists file:
add_subdirectory(Enjin-CPP-SDK)
target_link_libraries(my_target PRIVATE enjinsdk::enjinsdk)
Alternatively, on Linux you may include the SDK in your project by cloning and building it with the following commands:
$ git clone https://github.com/enjin/Enjin-CPP-SDK.git
$ cmake ./Enjin-CPP-SDK [options] && make -j -C ./Enjin-CPP-SDK
From here, you may use CMake's find_package()
function to find enjinsdk
and link the library, enjinsdk::enjinsdk
to your target.
For running unit tests Git (1.6.5+) is required to run CMake's ExternalProject_Add()
function
to acquire Googletest (1.10.0+) to be used as the testing framework.
To have the test executable built, set the CMake argument ENJINSDK_BUILD_TESTS
to ON
and leave the BUILD_TESTING
option from CTest enabled.
This example showcases how to quickly create and authenticate a client on the project schema which will then allow us to make further requests to the platform.
#include "enjinsdk/EnjinHosts.hpp"
#include "enjinsdk/ProjectClient.hpp"
#include <iostream>
#include <memory>
using namespace enjin::sdk;
using namespace enjin::sdk::graphql;
using namespace enjin::sdk::models;
using namespace enjin::sdk::project;
int main() {
// Builds the project client to run on the Kovan test network.
// See: https://kovan.cloud.enjin.io to sign up for the test network.
std::unique_ptr<ProjectClient> client = ProjectClientBuilder()
.base_uri(KOVAN) // From EnjinHosts
.build();
// Creates the request to authenticate the client.
// Replace the appropriate strings with the project's UUID and secret.
AuthProject req = AuthProject()
.set_uuid("<the-project's-uuid>")
.set_secret("<the-project's-secret>");
// Sends the request to the platform and gets the response.
GraphqlResponse<AccessToken> res = client->auth_project(req).get();
// Checks if the request was successful.
if (!res.is_successful()) {
std::cout << "AuthProject request failed" << std::endl;
return 0;
}
// Authenticates the client with the access token in the response.
client->auth(res.get_result().value().get_token().value());
// Checks if the client was authenticated.
if (client->is_authenticated()) {
std::cout << "Client is now authenticated" << std::endl;
} else {
std::cout << "Client was not authenticated" << std::endl;
}
return 0;
}
Contributions to the SDK are appreciated!
You can open issues for bugs and enhancement requests.
When reporting bugs, please state the OS, compiler, and CMake arguments used as well as reproducible examples if possible.
If you make any changes or improvements to the SDK, which you believe are beneficial to others, consider making a pull request to merge your changes to be included in the next release.
Ensure that tests are passing when running the target enjinsdk_tests
and add any necessary test classes or test cases
for your code.
Be sure to include your name in the list of contributors.
The license summary below may be copied.
Copyright 2021 Enjin Pte. Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.