Giter Club home page Giter Club logo

enjin-unreal-sdk's Introduction

Blockchain SDK by Enjin for Unreal Engine

Create blockchain projects and video games using Unreal Engine.

Learn more about the Enjin blockchain platform.

Sign up to Enjin Cloud: Goerli (Testnet), Mainnet (Production), or JumpNet.

Resources

Support

Contact Enjin support through email at [email protected] or submit a ticket at https://enjin.io/support.

Table of Contents

Compatibility

Platform Schemas

This SDK provides an API compatible with the V.2 schemas used on the Enjin Platform.

Unreal Engine

This SDK supports Unreal Engine 4.27 and Unreal Engine 5.

This SDK utilizes C++14 as its standard version.

Usage

Async Operations

Asynchronous operations performed by this SDK, such as HTTP requests and event processing via websockets, may not necessarily run on the Game Thread. As such, it is necessary to resynchronize when passing data to objects that are interacted with on the Game Thread, such as those in the Slate UI framework.

Quick Start

The below example shows how to setup and authenticate a player client for the player schema.

NOTE: AccessToken is expected to be retrieved from a game server connected as a project client to the Enjin Platform. This is to help keep the project's authentication credentials secured.

#include "EnjinHosts.h"
#include "PlayerClient.h"
#include "Model/AccessToken.h"

using namespace Enjin::Sdk;
using namespace Enjin::Sdk::Model;

// Withing the source file of an actor
void AExampleProject::BeginPlay()
{
    Super::BeginPlay();

    // Builds the player client to run on the Goerli test network.
    // See: https://goerli.cloud.enjin.io to sign up for the test network.
    // Client is a class member-field of type TUniquePtr<FPlayerClient>.
    Client = FPlayerClient::Builder()
        .BaseUrl(FEnjinHosts::Goerli())
        .Build();

    FAccessToken AccessToken = /* Retrieved from a game server. */;

    // Authenticates the client with the access token.
    Client->Auth(AccessToken.GetToken().GetValue());

    // Checks if the client was authenticated.
    if (Client->IsAuthenticated())
    {
        UE_LOG(LogTemp, Display, TEXT("Client is now authenticated"));
    }
    else
    {
        UE_LOG(LogTemp, Display, TEXT("Client was not authenticated"));
    }
}

For immediate setup and testing, a project client that has access to project schema requests may be setup in the game instance as shown below.

This is NOT recommended for anything beyond internal testing, due to possible exposure of the project's credentials and the game instance ought to be setup to use a player client as soon as possible.

#include "EnjinHosts.h"
#include "GraphQlResponse.h"
#include "ProjectClient.h"
#include "Model/AccessToken.h"
#include "Project/AuthProject.h"

using namespace Enjin::Sdk;
using namespace Enjin::Sdk::GraphQl;
using namespace Enjin::Sdk::Model;
using namespace Enjin::Sdk::Project;

// Withing the source file of an actor
void AExampleProject::BeginPlay()
{
    Super::BeginPlay();

    // Builds the project client to run on the Goerli test network.
    // See: https://goerli.cloud.enjin.io to sign up for the test network.
    // Client is a class member-field of type TUniquePtr<FProjectClient>.
    Client = FProjectClient::Builder()
        .BaseUrl(FEnjinHosts::Goerli())
        .Build();

    // Creates the request to authenticate the client.
    // Replace the appropriate strings with the project's UUID and secret.
    FAuthProject Req = FAuthProject()
        .SetUuid(TEXT("<the-project's-uuid>"))
        .SetSecret(TEXT("<the-project's-secret>"));

    // Sends the request to the platform and gets the response.
    Client->AuthProject(Req).Next([this](TGraphQlResponseForOnePtr<FAccessToken> Res)
    {
        if (!Res.IsValid() || !Res->IsSuccessful())
        {
            UE_LOG(LogTemp, Display, TEXT("AuthProject request failed"));
            return;
        }

        // Authenticates the client with the access token.
        Client->Auth(Res->GetResult().GetValue().GetToken().GetValue());

        // Checks if the client was authenticated.
        if (Client->IsAuthenticated())
        {
            UE_LOG(LogTemp, Display, TEXT("Client is now authenticated"));
        }
        else
        {
            UE_LOG(LogTemp, Display, TEXT("Client was not authenticated"));
        }
    });
}

enjin-unreal-sdk's People

Contributors

bishopjohnson avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

leejw51

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.