> For the complete documentation index, see [llms.txt](https://sending-network.gitbook.io/sending.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sending-network.gitbook.io/sending.network/sdk-documentation/unity-sdk.md).

# Unity SDK

This guide will walk you through the necessary steps to get started with SendingNetwork requests using the SDK.

## Prerequisites

Before you begin, please ensure that you have the following prerequisites:

* [.NET Standard 2.0](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) or greater installed on your development machine.

## Installation

To install the SDK, you can use either NuGet package manage:

```shell
dotnet add package SDN.Sdk
```

## Use the SDK in your app

### 1. Create

Use `SDNClientFactory` to create an instance of `SDNClient`.

```csharp
var factory = new SDNClientFactory();
ISDNClient client = factory.Create();
```

### 2.Login

Currently, `SDNClient` supports only wallet account login.

```csharp
// pre-login
var preLoginResponse = await client.PreLoginAsync(new Uri(nodeUrl), walletAddress);

// sign message (or prompt user to sign with a wallet app)
var signer = new EthereumMessageSigner();
var signature = signer.EncodeUTF8AndSign(preLoginResponse.Message, new EthECKey(privateKey));

// login did
var loginResponse = await client.LoginAsync(preLoginResponse.Did, preLoginResponse.RandomServer, preLoginResponse.Updated, preLoginResponse.Message, signature);
                userId = loginResponse.UserId;
                accessToken = loginResponse.AccessToken;

// set client credential
client.SetCredential(new Uri(nodeUrl), loginResponse.UserId, loginResponse.AccessToken);
```

### 3. Start listening for incoming events

To listen for the incoming room events you need to subscribe to `OnSDNRoomEventsReceived`.

```csharp
// add event listener
client.OnSDNRoomEventsReceived += (sender, eventArgs) =>
{
    foreach (var roomEvent in eventArgs.SDNRoomEvents)
    {
        if (roomEvent is TextMessageEvent textMessageEvent)
        {
            Console.WriteLine($"RoomId: {textMessageEvent.RoomId} received event from {textMessageEvent.SenderUserId}: {textMessageEvent.Message}.");
        }
    }
};

// start syncing
client.Start();
```

### 4. Call API functions

```csharp
// create new room
await client.CreateRoomAsync(roomName, null);

// invite user to the room
await client.InviteUserAsync(roomId, userId);

// send room message
await client.SendMessageAsync(roomId, "hello");
```

## Examples

For a complete example, refer to *Sample.cs*. You can also clone this repository and run `SDN.Sdk.Sample.Console`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sending-network.gitbook.io/sending.network/sdk-documentation/unity-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
