Skip to content

Latest commit

 

History

History
127 lines (102 loc) · 3.88 KB

README.md

File metadata and controls

127 lines (102 loc) · 3.88 KB

BNBParty.GraphQL

BNBParty.GraphQL is a library for interacting with BNBParty.GraphQL project's GraphQL endpoint. It allows you to perform queries to the GraphQL server and retrieve data.

Installation

Clone the repository:

git clone https://github.com/The-Poolz/BNBParty.GraphQL.git
cd src/BNBParty.GraphQLClient

Usage

  1. Adding the Library Add a reference to the library in your project:

    dotnet add reference ../BNBParty.GraphQL
    
  2. Add necessary packages:

    dotnet add package Flurl.Http
    dotnet add package Newtonsoft.Json
    

Example Usage

Here is a basic example of how to use the library to perform queries to the GraphQL server:

using BNBParty.GraphQLClient;
using BNBParty.CodeGen.Generated.Types;
using System;
using System.Threading.Tasks;

namespace GraphQLClient.Test
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var endpoint = "https://origin/graphql";
            var apiKey = "origin";
            var client = new GraphQlClient(endpoint, apiKey);

            try
            {
                // Example of GetToken query
                var getTokenResponse = await client.GetTokenAsync(3);
                if (getTokenResponse?.data?.getToken != null)
                {
                    var token = getTokenResponse.data.getToken;
                    Console.WriteLine($"Token ID: {token.tokenId}");
                    Console.WriteLine($"Token Address: {token.tokenAddress}");
                }

                // Example of InsertToken mutation
                var chainId = 97;
                var txHash = "0x212d6de7f588b193a492ff89faa387806cdca26bb5a07ff1ce860d9d0630d285";
                var insertTokenResponse = await client.InsertTokenAsync(chainId, txHash);
                Console.WriteLine($"Inserted Token ID: {insertTokenResponse.data.insertToken.tokenId}");
                Console.WriteLine($"Is New: {insertTokenResponse.data.insertToken.isNew}");

                // Example of GenerateAuth mutation
                var generateAuthResponse = await client.GenerateAuthAsync("someSign", "someMessage");
                Console.WriteLine($"Generated Auth: {generateAuthResponse.data.generateAuth}");

                // Example of UpdateTokenContent mutation
                var tokenToUpdate = new Token
                {
                    tokenId = 123,
                    offChainData = new OffChainData
                    {
                        content = "new content",
                        icon = "new icon",
                        likeCounter = 10,
                        Discord = "discord_link",
                        Telegram = "telegram_link",
                        Website = "website_link",
                        X = "x_link"
                    }
                };
                var updateTokenContentResponse = await client.UpdateTokenContentAsync(tokenToUpdate);
                Console.WriteLine($"Updated Token ID: {updateTokenContentResponse.data.updateTokenContent.tokenId}");
                Console.WriteLine($"Updated Content: {updateTokenContentResponse.data.updateTokenContent.offChainData.content}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
    }
}

Methods

GetTokenAsync Query to retrieve information about a token by its ID.

public async Task<GetTokenResponse> GetTokenAsync(int tokenId);

InsertTokenAsync Mutation to insert a new token.

public async Task<InsertTokenResponse> InsertTokenAsync(long chainId, string txHash);

GenerateAuthAsync Mutation to generate an authorization token.

public async Task<GenerateAuthResponse> GenerateAuthAsync(string sign, string message);

UpdateTokenContentAsync Mutation to update the content of a token.

public async Task<UpdateTokenContentResponse> UpdateTokenContentAsync(Token token);