GithubHelp home page GithubHelp logo

enjin / enjin-csharp-sdk Goto Github PK

View Code? Open in Web Editor NEW
29.0 7.0 11.0 2.02 MB

Enjin Cloud SDK for C#.

Home Page: https://enjin.io/products/platform

License: Apache License 2.0

C# 100.00%
csharp enjin-platform enjin-sdk sdk-csharp sdk blockchain blockchain-sdk nft nfts non-fungible-tokens

enjin-csharp-sdk's Introduction

Blockchain SDK by Enjin for C#

NuGet Tests

Create blockchain video games and applications using the C# programming language.

Learn more about the Enjin blockchain platform.

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

Resources

Table of Contents

Compatibility

The Enjin C# SDK is targeted for .NET Standard 2.0.

Installation

This SDK is available on NuGet and may be installed with the following package manager command:

PM> Install-Package Enjin.Sdk.CSharp

Quick Start

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.

using System;
using Enjin.SDK;
using Enjin.SDK.Graphql;
using Enjin.SDK.Models;
using Enjin.SDK.ProjectSchema;

public static class Program
{
    public static void Main()
    {
        // Builds the project client to run on the Kovan test network.
        // See: https://goerli.cloud.enjin.io to sign up for the test network.
        ProjectClient client = ProjectClient.Builder()
                                            .BaseUri(EnjinHosts.GOERLI)
                                            .Build();

        // Creates the request to authenticate the client.
        // Replace the appropriate strings with the project's UUID and secret.
        AuthProject req = new AuthProject()
            .Uuid("<the-project's-uuid>")
            .Secret("<the-project's-secret>");

        // Sends the request to the platform and gets the response.
        GraphqlResponse<AccessToken> res = client.AuthProject(req).Result;

        // Checks if the request was successful.
        if (!res.IsSuccess)
        {
            Console.Out.WriteLine("AuthProject request failed");
            client.Dispose();
            return;
        }

        // Authenticates the client with the access token in the response.
        client.Auth(res.Result.Token);

        // Checks if the client was authenticated.
        if (client.IsAuthenticated)
        {
            Console.Out.WriteLine("Client is now authenticated");
        }
        else
        {
            Console.Out.WriteLine("Client was not authenticated");
        }

        // Dispose client as part of cleanup and free any resources.
        client.Dispose();
    }
}

Contributing

Contributions to the SDK are appreciated!

Issues

You can open issues for bugs and enhancement requests.

Pull Requests

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 TestSuite and add any necessary test classes or test cases for your code.

Be sure to include your name in the list of contributors.

Copyright and Licensing

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.

enjin-csharp-sdk's People

Contributors

bishopjohnson avatar bradez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

enjin-csharp-sdk's Issues

Imported in Unity Broken Project Missing Libraries

We get all errors on importing the Project inside Unity. PusherClient is not defined and many more, could you please fix it ? It would be useful if you create a proper Unity doc/SDK since it's the number one game engine out there! Thanks!

image

GetWallet missing balances

The result object for GetWallet does not have balances property. I can't workout how to see the NFT's on an ethAddress the same as the graphql below returns in the playground.

query {
GetWallet(ethAddress: "0x854Cd273c80eF85C3e674B0637AB067b962744F2") {
ethAddress
enjAllowance
enjBalance
ethBalance
balances {
asset{name}
id
index
value
project {
name
}
}
assetsCreated {
id
items {
name
id
}
}
}
}

No Reference for Builder() in ProjectClient class

So the 'Quick Start' guide has:
ProjectClient client = ProjectClient.Builder().BaseUri(EnjinHosts.KOVAN).Build();
For me at least, I'm getting an error that Project Client does not contain a definition for Builder()

Bug with DeletePlayer

As per the error below the DeletePlayer method says it returns a bool but it looks like it infact returns a null and that then can not be converted to a boolean.

crit: Enjin-SDK[0]
      An error occured while processing a request or a response.
      System.ArgumentException: Can not convert Null to Boolean.
         at Newtonsoft.Json.Linq.JToken.op_Explicit(JToken value)
         at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
         at Newtonsoft.Json.Linq.JToken.ToObject[T]()
         at Enjin.SDK.Graphql.GraphqlData`1.ProcessJsonResult(JToken result)
         at lambda_method96(Closure , Object[] )
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ResolvePropertyAndCreatorValues(JsonObjectContract contract, JsonProperty containerProperty, JsonReader reader, Type objectType)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObjectUsingCreatorWithParameters(JsonReader reader, JsonObjectContract contract, JsonProperty containerProperty, ObjectConstructor`1 creator, String id)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
         at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
         at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
         at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
         at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
         at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
         at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
         at Enjin.SDK.BaseSchema.<SendRequest>b__12_0[T](Task`1 task)

Query is not being compiled in CreateRequestBody method

I'm currently trying this out in unity and I notice that the query variable within the CreateRequestBody method that's located in the BaseSchema.cs file is not compiling the query, but the variables variable is generating the input properly.

On a side note: Base on what I have gathered so far, I wouldn't be able to really do anything anyways assuming that most of the current GraphQL are for the early access api correct (i.e. AuthProject is an early access GraphQL query)?

Syntax Error: Unexpected <EOF> when trying to get access token

I added my project on Jumpnet. UUID : 7577d864-9b88-443c-8897-8d3e941dfb9c

I can use the GraphQL Playground just fine to make a call to https://jumpnet.cloud.enjin.io/graphql/project,
passing in the UUID and secret, and getting back the access token.

But when I do the same using the C# SDK, I get the following error...
Syntax Error: Unexpected

ProjectClient client = new ProjectClient(EnjinHosts.JUMP_NET);
            
            AuthProject project = new AuthProject()
                .Uuid("7577d864-9b88-443c-8897-8d3e941dfb9c")
                .Secret("xxxxx");

            GraphqlResponse<AccessToken> res = client.AuthProject(project).Result;

Any ideas?

Event streams

Firstly i wanted to say that they look extreamly useful but i see one main issue with them. If you build your application to rely on them then you need to be able to deal with the case when the reader crashes or looses connection and needs to resume. If not you would need to ge thte state of everything when you restart the app or process. To me it seems like it could be ideal to be able to specify the events you are interested in from a block going forward or something like that and you have the events report the block so you can keep track of where you are up to and resume from there once connection is back or your app is back up again.

If developers could do something like that then i could see a lot of the API calls not being needed for queries and managing local state that is in sync with the blockchain would be a lot easier.

Authentication

I am only starting to play with the library so i may have missed something but the auth workflow feels a little wrong to me. When we authenticate a project or a player Enjin returns a JWT token that is valid for 24 hours and then i beleive you need to renew it using the original authentication method as i assume you can't refresh the token using the token. For a short running program this is not an issue but for a server side program that may run for days, weeks or months it would be.bFrom what i can tell the clients don't really have anything in there to manage this or help with this and instead the developer needs to code it all and i would think it would be common task for almost anyone using the lib.

Perhaps you could have an Authentication Helper or something that could optionally be passed to the clients when created that could do the token management and refresh for the client by taking in the AuthProject UUID and Secret from config or some other source like a secret store. If the project auth is going to expire in say 30 minutes it will create a project client and get a new auth token to be used by all project clients that use the AuthHelper. For the playerClient i think it is a little more complex as as to refresh those you need the project aith token and the player details but the authhelper could provide the project token needed and i would think the player details would be in the player token since they are jwt tokens.

honestly i have not quite understood yet when you would use the player access token vs just using the access token for the project as it seems like you cna do most things if not all on the project in relation to the players. I get the reason froma security side of things but if their tokens expire then you still need to project level auth token to keep getting the players tokens so does not really let you seperate things out unless you do it at login one time or something as normally a user should be online for less than 24 hours

README.md doesn't exist?

This sounds weird but when I just clone without adding anything and build
it says I don't have README.md? Following is the exact message.

NU5039 The readme file 'README.md' does not exist in the package.

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.