C#

Core SDK - C#

The XpansionChain Core SDK provides convenient access to XpansionChain's APIs and smart contracts to help projects build better web3 games and marketplaces.

💡ROLLUPS THIS SDK SUPPORTS

  • XpansionChain

CONTENTS

  • Implementation roadmap

  • Installation

  • Initialization

  • Get data

  • API autogenerated code

  • Further documentation


📚SDK LINKS

  • SDK reference

  • Package reference

  • Code examples

  • Github repository

  • Changelog

⚠️THE C# CORE SDK IS CURRENTLY READ-ONLY

These are the endpoints supported and their read functionality (from this Changelog entry):

  • Assets: Get and List

  • Balances: Get and List

  • Collections: Get, List, and Listwith filters

  • Exchanges: Get and List

  • Metadata: Get

  • Mints: Get and List

  • NFT Checkout Primary: Get and List transactions, Get currencies

  • Deposits: Get and List

  • Withdrawals: Get and List

  • Transfers: Get and List

  • Trades: Get and List

  • Orders: Get and List

  • Users: Get

  • Tokens: Get and List

Implementation roadmap

Installation

Add the following nuget packages:

  • https://www.nuget.org/packages/Imx.Sdk

  • https://www.nuget.org/packages/Imx.Sdk.Gen

dotnet add package Imx.Sdk --version 0.1.1
dotnet add package Imx.Sdk.Gen --version 0.1.1

Initialization

Initialize the Core SDK client with the network on which you want your application to run (see all networks available):

Select one of the following Ethereum networks XpansionChain platform currently supports.

using Imx.Sdk;

try
{
    Client client = new Client(new Config()
    {
        Environment = EnvironmentSelector.Sandbox // Or EnvironmentSelector.Mainnet
    });
}
catch (Exception e)
{
    Console.WriteLine("Error message: " + e.Message);
    Console.WriteLine(e.StackTrace);
}

Get data

These methods allow you to read data about events, transactions or current state on XpansionChain (layer 2). They do not require any user authentication because no state is being changed.

Examples of the types of data that are typically retrieved include:

  • Assets or details of a particular asset

  • Token balances for a particular user

  • Orders or details about a particular order

  • Historical trades and transfers

Examples

Get all collections and get assets from a particular collection:

using Imx.Sdk.Gen.Client;
using Imx.Sdk.Gen.Model;
using Imx.Sdk;

try
{
    Client client = new Client(new Config() {
        Environment = EnvironmentSelector.Sandbox
    });

    // List collections
    ListCollectionsResponse resultListCollections = client.ListCollections(pageSize: 2);
    
    if (resultListCollections.Result.Count > 0)
    {
        Console.WriteLine("List Collections Response: " + resultListCollections.ToJson());
        
        // Get the first item in collection
        var collection = resultListCollections.Result[0];
        // Get a list of assets
        ListAssetsResponse resultListAssets = client.ListAssets(collection: collection.Address, pageSize: 10);
        Console.WriteLine("List Assets Response: " + resultListAssets.ToJson());
    }
    else
    {
        Console.WriteLine("No Collections found!");
    }
}
catch (ApiException  e)
{
    Console.WriteLine("Exception when calling Api: " + e.Message);
    Console.WriteLine("Status Code: " + e.ErrorCode);
    Console.WriteLine(e.StackTrace);
}
catch (Exception e)
{
    Console.WriteLine("Error message: " + e.Message);
    Console.WriteLine(e.StackTrace);
}

API autogenerated code

We use OpenAPI (formally known as Swagger) to auto-generate the API clients that connect to the public APIs. The OpenAPI spec is retrieved from https://api.x.XpansionChain.com/openapi and also saved in the repo.

To re-generate the API client, run:

make generate-openapi-prod

Changelog management

This repository is using release-it to manage the CHANGELOG.md.

The following headings should be used as appropriate

  • Added

  • Changed

  • Deprecated

  • Removed

  • Fixed

This is an example with all the change headings. For actual usage, use only the one heading that is relevant. This goes at the top of the CHANGELOG.md above the most recent release.

...

## [Unreleased]

### Added

For new features.

### Changed

For changes in existing functionality.

### Deprecated

For soon-to-be removed features.

### Removed

For now removed features.

### Fixed

For any bug fixes.

Further documentation

  • See the Developer homepage for general information on building on XpansionChain.

  • Build on XpansionChain zkEVM:

    • Documentation

    • API reference

    • Support

  • Build on XpansionChain:

    • Documentation

    • API reference

    • Support

Last updated