# Examples

You can check outthe  example code in the package at `Assets/NEGdk/Sample/NEGdkSample.ts`

## Initialize the GDK

```csharp
NEGdk.Instance.Initialize((errorCode) => {
    if (errorCode == 0) {
        // Init success
        if (NEGdk.Instance.IsLoggedIn()) {
            // Already login using cache, you can fetch user data now
        } else {
            // Not login yet
        }
    } else {
        // Init failed
    }
});
```

## Login

### Social Login

```csharp
NEGdk.Instance.LoginWithProvider("google", (errorCode, loginData) => {
    if (errorCode == 0) {
        // Login success
        var profile = loginData.profile;
    } else {
        // Login failed
    }
});
```

#### Create/Restore Wallet

```csharp
var phrase = NEGdk.Instance.CreateWallet();
NEGdk.Instance.LoginWithPhrase(phrase, (errorCode, loginData) => {
    if (errorCode == 0) {
        // Login success
        var profile = loginData.profile;
    } else {
        // Login failed
    }
});
```

#### Logout

```csharp
NEGdk.Instance.Logout();
```

### Get User Pets Data

```csharp
NEGdk.Instance.RequestUserPets((response) => {
    if (response.errorCode == 0) {
        // get user pets success
        var pets = response.data;
    } else {
        // get user pets failed, check errorCode for reason
    }
});
```

### Get User Balances Data

```csharp
NEGdk.Instance.RequestUserBalances((response) => {
    if (response.errorCode == 0) {
        // get user balances success
        var balances = response.data;
    } else {
        // get user balances failed, check errorCode for reason
    }
});
```

### Get Shop Info

```csharp
NEGdk.Instance.RequestShopinfo((response) => {
    if (response.errorCode == 0) {
        // get shop info success
        var shopPacks = response.data;
    } else {
        // get shop info failed, check errorCode for reason
    }
});
```

### Buy a Pack in the shop

```csharp
var packId = 26;
var amount = 1;
var currency = "SPACE_STONE";
NEGdk.Instance.BuyShopPack(packId, amount, currency, response => {
    if (response.errorCode == 0) {
        // Buy success
        var remainBalance = response.data;
    } else {
        // Buy failed, check error code for reason
    }
});
```


---

# Agent Instructions: 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:

```
GET https://docs.eternals.game/gdk-documentation/unity/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
