Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Merit-Circle/beam-csharp

Repository files navigation

Beam - the C# library for the Beam game development API

The Beam game development API is a service to integrate your game with Beam

This C# SDK is automatically generated by the OpenAPI Generator project:

  • API version: 1.0.0
  • SDK version: 1.0.0
  • Build package: org.openapitools.codegen.languages.CSharpClientCodegen

Frameworks supported

Dependencies

The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:

Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
Install-Package System.ComponentModel.Annotations

Installation

Run the following command to generate the DLL

  • [Mac/Linux] /bin/sh build.sh
  • [Windows] build.bat

Then include the DLL (under the bin folder) in the C# project, and use the namespaces:

using Beam.Api;
using Beam.Client;
using Beam.Model;

Packaging

A .nuspec is included with the project. You can follow the Nuget quickstart to create and publish packages.

This .nuspec uses placeholders from the .csproj, so build the .csproj directly:

nuget pack -Build -OutputDirectory out Beam.csproj

Then, publish to a local feed or other host and consume the new package via Nuget as usual.

Usage

To use the API client with a HTTP proxy, setup a System.Net.WebProxy

Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;

Connections

Each ApiClass (properly the ApiClient inside it) will create an instance of HttpClient. It will use that for the entire lifecycle and dispose it when called the Dispose method.

To better manager the connections it's a common practice to reuse the HttpClient and HttpClientHandler (see here for details). To use your own HttpClient instance just pass it to the ApiClass constructor.

HttpClientHandler yourHandler = new HttpClientHandler();
HttpClient yourHttpClient = new HttpClient(yourHandler);
var api = new YourApiClass(yourHttpClient, yourHandler);

If you want to use an HttpClient and don't have access to the handler, for example in a DI context in Asp.net Core when using IHttpClientFactory.

HttpClient yourHttpClient = new HttpClient();
var api = new YourApiClass(yourHttpClient);

You'll loose some configuration settings, the features affected are: Setting and Retrieving Cookies, Client Certificates, Proxy settings. You need to either manually handle those in your setup of the HttpClient or they won't be available.

Here an example of DI setup in a sample web project:

services.AddHttpClient<YourApiClass>(httpClient =>
   new PetApi(httpClient));

Getting Started

using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using Beam.Api;
using Beam.Client;
using Beam.Model;

namespace Example
{
    public class Example
    {
        public static void Main()
        {

            Configuration config = new Configuration();
            config.BasePath = "http://localhost";
            // Configure API key authorization: Beam API game key
            config.ApiKey.Add("x-api-key", "YOUR_API_KEY");
            // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
            // config.ApiKeyPrefix.Add("x-api-key", "Bearer");

            // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes
            HttpClient httpClient = new HttpClient();
            HttpClientHandler httpClientHandler = new HttpClientHandler();
            var apiInstance = new AssetsApi(httpClient, config, httpClientHandler);
            var assetAddress = "assetAddress_example";  // string | 
            var assetId = "assetId_example";  // string | 
            var chainId = 8.14D;  // decimal? |  (optional) 
            var entityId = "entityId_example";  // string? |  (optional) 

            try
            {
                // Get a single NFT (e.g. ERC721 / ERC1155)
                GetAssetResponse result = apiInstance.GetAsset(assetAddress, assetId, chainId, entityId);
                Debug.WriteLine(result);
            }
            catch (ApiException e)
            {
                Debug.Print("Exception when calling AssetsApi.GetAsset: " + e.Message );
                Debug.Print("Status Code: "+ e.ErrorCode);
                Debug.Print(e.StackTrace);
            }

        }
    }
}

Documentation for API Endpoints

All URIs are relative to http://localhost

Class Method HTTP request Description
AssetsApi GetAsset GET /v1/assets/{assetAddress}/{assetId} Get a single NFT (e.g. ERC721 / ERC1155)
AssetsApi GetContractAssets GET /v1/assets/{assetAddress} Get all the assets of contract (NFT assets, e.g. ERC721 / ERC1155)
AssetsApi GetContractAssetsPost POST /v1/assets/{assetAddress} Get all the assets of contract (NFT assets, e.g. ERC721 / ERC1155)
AssetsApi GetProfileAssetsForGame GET /v1/assets/profiles/{entityId} Get all the assets of a profile (NFT assets, e.g. ERC721 / ERC1155)
AssetsApi GetProfileAssetsForGamePost POST /v1/assets/profiles/{entityId} Get all the assets of a profile (NFT assets, e.g. ERC721 / ERC1155)
AssetsApi GetProfileCurrencies GET /v1/assets/profiles/{entityId}/currencies Get all the currencies owned by an account (ERC20)
AssetsApi GetProfileNativeCurrency GET /v1/assets/profiles/{entityId}/native Get the native token balance
AssetsApi TransferAsset POST /v1/assets/profiles/{entityId}/transfer-asset Transfer an asset (NFT assets, ERC721 / ERC1155)
AssetsApi TransferNativeToken POST /v1/assets/profiles/{entityId}/transfer-native Transfer the native token (MC)
AssetsApi TransferToken POST /v1/assets/profiles/{entityId}/transfer-token Transfer a token (token assets, ERC20)
ChainApi Chain GET /v1/chain
ChainApi EstimateProfileTransactionGas POST /v1/chain/estimate/profiles/{entityId}/transaction Estimate gas fee for a transaction on behalf of a profile
ExchangeApi ConvertInput POST /v1/exchange/profiles/{entityId}/convert/input Trade an exact amount of tokenIn for a minimum amount of tokenOut
ExchangeApi ConvertToOutput POST /v1/exchange/profiles/{entityId}/convert/output Swap a maximum amount of tokenIn for an exact amount of tokenOut
ExchangeApi GetQuoteForInput GET /v1/exchange/quote/input Returns the maximum necessary input amount for a token trade, given a desired output amount
ExchangeApi GetQuoteForOutput GET /v1/exchange/quote/output Returns the minimum expected output amount for a token trade, given an input amount
GameApi AddContractToGame POST /v1/game/contracts Add a new contract to the game
GameApi GetGame GET /v1/game Get information about your game
GameApi RegenerateApiKeys POST /v1/game/regenerate-api-keys Regenerate API keys
GameApi RemoveContractFromGame DELETE /v1/game/contracts/{address}/{chainId} Delete a contract from a game
GameApi UpdateGame PATCH /v1/game Updating name, description and/or coverImageUrl
MarketplaceApi AcceptAssetOffer POST /v1/marketplace/profiles/{entityId}/offers/{offerId}/accept Accept an offer for an asset
MarketplaceApi BuyListedAsset POST /v1/marketplace/profiles/{entityId}/listing/{orderId} Buy listed asset
MarketplaceApi CancelAssetOffer DELETE /v1/marketplace/profiles/{entityId}/offers/{offerId} Cancel an offer for an asset
MarketplaceApi CancelListing DELETE /v1/marketplace/profiles/{entityId}/listing/{orderId} Cancel asset listing
MarketplaceApi CreateAssetOffer POST /v1/marketplace/profiles/{entityId}/offers Make an offer for an asset
MarketplaceApi GetAssetOffers GET /v1/marketplace/offers/asset/{marketplaceId} Get all offers for an asset
MarketplaceApi GetChainCurrencies GET /v1/marketplace/chain-currencies/{chainId}
MarketplaceApi GetListedAssets GET /v1/marketplace Get all listed assets for a game (NFT assets, e.g. ERC721 / ERC1155)
MarketplaceApi GetListedAssetsForProfile GET /v1/marketplace/profiles/{entityId} Get all the assets listed by a profile (NFT assets, e.g. ERC721 / ERC1155)
MarketplaceApi GetListedAssetsForProfilePost POST /v1/marketplace/profiles/{entityId} Get all the assets listed by a profile (NFT assets, e.g. ERC721 / ERC1155)
MarketplaceApi GetListedAssetsPost POST /v1/marketplace Get all listed assets for a game (NFT assets, e.g. ERC721 / ERC1155)
MarketplaceApi GetPlayerAssetOffers GET /v1/marketplace/profiles/{entityId}/offers/asset/{marketplaceId} Get all asset offers that player created
MarketplaceApi GetPlayerOffers GET /v1/marketplace/profiles/{entityId}/offers Get all offers that player created
MarketplaceApi ListAsset POST /v1/marketplace/profiles/{entityId}/listing List an asset for sale
PolicyApi CreatePolicy POST /v1/policies Add a new policy to sponsor web3 actions
PolicyApi DeletePolicy DELETE /v1/policies/{policyId} Removing a policy that sponsors web3 actions
PolicyApi GetPolicies GET /v1/policies Get a list of policies
ProfilesApi CreateConnectionRequest POST /v1/profiles/{entityId}/create-connection-request Generates a challenge which can be encoded in a QR code / app link for the user to take control of the profile
ProfilesApi CreateProfile POST /v1/profiles Creating a profile
ProfilesApi CreateSignInRequest POST /v1/profiles/{entityId}/create-sign-in-request Generates a challenge which can be encoded in a QR code / app link for the user to sign in to the game
ProfilesApi GetAllProfiles GET /v1/profiles Getting all profiles
ProfilesApi GetProfile GET /v1/profiles/{entityId} Getting information on a profile
ProfilesApi UpdateProfile PATCH /v1/profiles/{entityId} Update a profile
TransactionsApi CreateProfileTransaction POST /v1/transactions/profiles/{entityId} Creating a new transaction on behalf of a profile
TransactionsApi GetProfileTransactions GET /v1/transactions/profiles/{entityId} Get a paginated list of transactions created on behalf of a profile
TransactionsApi GetTransaction GET /v1/transactions/{transactionId} Getting a transaction
TransactionsApi GetTransactions GET /v1/transactions Get a paginated list of transactions from your game

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API:

Beam API game key

  • Type: API key
  • API key parameter name: x-api-key
  • Location: HTTP header

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages