# 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

* <mark style="color:blue;">Implementation roadmap</mark>
* <mark style="color:blue;">Installation</mark>
* <mark style="color:blue;">Initialization</mark>
* <mark style="color:blue;">Get data</mark>
* <mark style="color:blue;">API autogenerated code</mark>
* <mark style="color:blue;">Further documentation</mark>

***

📚SDK LINKS

* <mark style="color:blue;">SDK reference</mark>
* <mark style="color:blue;">Package reference</mark>
* <mark style="color:blue;">Code examples</mark>
* <mark style="color:blue;">Github repository</mark>
* <mark style="color:blue;">Changelog</mark>

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

These are the endpoints supported and their read functionality (from <mark style="color:blue;">this Changelog entry</mark>):

* **Assets**: `Get` and `List`
* **Balances**: `Get` and `List`
* **Collections**: `Get`, `List`, and `List`with 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[​](https://docs.x.immutable.com/docs/sdks/core/csharp#implementation-roadmap) <a href="#implementation-roadmap" id="implementation-roadmap"></a>

![image](https://docs.x.immutable.com/assets/images/unityRoadmap-f838136cd65f1d91df2d7c2384d388b5.jpeg)

### Installation[​](https://docs.x.immutable.com/docs/sdks/core/csharp#installation) <a href="#installation" id="installation"></a>

Add the following nuget packages:

* <mark style="color:blue;"><https://www.nuget.org/packages/Imx.Sdk></mark>
* <mark style="color:blue;"><https://www.nuget.org/packages/Imx.Sdk.Gen></mark>

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

### Initialization[​](https://docs.x.immutable.com/docs/sdks/core/csharp#initialization) <a href="#initialization" id="initialization"></a>

Initialize the Core SDK client with the network on which you want your application to run (see <mark style="color:blue;">all networks available</mark>):

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

| Environment | Description                                        |
| ----------- | -------------------------------------------------- |
| Sandbox     | The default test network (currently, it is Goërli) |
| Mainnet     | Ethereum network                                   |

```
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[​](https://docs.x.immutable.com/docs/sdks/core/csharp#get-data) <a href="#get-data" id="get-data"></a>

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[​](https://docs.x.immutable.com/docs/sdks/core/csharp#examples) <a href="#examples" id="examples"></a>

**Get all collections and get assets from a particular collection:**[**​**](https://docs.x.immutable.com/docs/sdks/core/csharp#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[​](https://docs.x.immutable.com/docs/sdks/core/csharp#api-autogenerated-code) <a href="#api-autogenerated-code" id="api-autogenerated-code"></a>

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

To re-generate the API client, run:

```
make generate-openapi-prod
```

#### Changelog management[​](https://docs.x.immutable.com/docs/sdks/core/csharp#changelog-management) <a href="#changelog-management" id="changelog-management"></a>

This repository is using <mark style="color:blue;">release-it</mark> 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[​](https://docs.x.immutable.com/docs/sdks/core/csharp#further-documentation) <a href="#further-documentation" id="further-documentation"></a>

* See the <mark style="color:blue;">Developer homepage</mark> for general information on building on XpansionChain.
* Build on XpansionChain zkEVM:
  * <mark style="color:blue;">Documentation</mark>
  * <mark style="color:blue;">API reference</mark>
  * <mark style="color:blue;">Support</mark>
* Build on XpansionChain:
  * <mark style="color:blue;">Documentation</mark>
  * <mark style="color:blue;">API reference</mark>
  * <mark style="color:blue;">Support</mark>
