# MindLake

## 1. connect() Method

Connect to Mind Lake while ensuring that all encryption keys are prepared and available. Prior to making any function calls within the SDK, execute this function as it serves as the entry point.

```typescript
const mindLake = await MindLake.getInstance(appKey);
const res = await mindLake.connect(chainId);
```

### Parameters

1. `appKey` - `string`: used for authorization, allowing users of your application to gain access to Mind Lake. **As a developer, you can apply for APP Keys from Mind Scan.**
2. `chainId`- `string|number`: the ID of the supported chain.

### Returns

An object of `Promise<`[`ResultType`](#user-content-fn-1)[^1]`>`. [For more information](#2.-resulttype-type).

{% hint style="info" %}
**Wallet Interaction**

During the 'Connect' procedure, the wallet will prompt the user 2-3 times as follows:

1. Sign a nonce for login authentication.

<img src="/files/9vyGMcUosGtZQyuIn15t" alt="" data-size="original">

**If the user's account keys are already on the chain:**

2. Decrypt the user's account keys using the wallet's private key.

<img src="/files/BYx07c54ayecjDuGrkgx" alt="" data-size="original">

**If the user's account keys do not exist yet:**

2. Obtain the public key of the wallet, which is used to encrypt the randomly generated account keys.

<img src="/files/7azSnAjV4HFLcuHklUnF" alt="" data-size="original">

3. Sign the transaction to upload the encrypted key ciphers to the smart contract on the chain.

<img src="/files/0ZqAFljh741IfLHOos4e" alt="" data-size="original">
{% endhint %}

### Example

```typescript
const mindLake = await MindLake.getInstance("YOUR_OWN_APP_KEY");
//"5" is example of Goerli Testnet chainId
const chainId = "5"
const res = await mindLake.connect(chainId);
```

## 2. MindLake.ResultType

Every method call in the Mind Lake SDK returns an object of ResultType.

```typescript
type ResultType = {
  code: number,
  message?: string,
  result?: any
}
```

* `code` - `number`: The return code of the method call. A return value of 0 indicates success, while non-zero values represent a specific error code.
* `message` - `string`: If the return code is non-zero, an error message will be provided to describe the specific error encountered during the method call.
* `result` - `any`: If a method call returns a result, it will be stored in the `result` field.

## 3. MindLake.DataType

The `DataType` enum defines a comprehensive range of supported data types. This enum can be used in conjunction with the `MindLake.DataLake.Column` class, which represents a single column in a table, to specify the data type of the column. By utilizing the `DataType` enum, you can ensure that your data is stored in the appropriate format and can be processed correctly by the system.

### Members

1. int4
2. int8
3. float4
4. float8
5. decimal
6. text
7. timestamp

[^1]: ```typescript
    type ResultType = {
      code: number,
      message?: string,
      result?: any
    }
    ```


---

# 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.mindnetwork.xyz/mind-lake-sdk/typescript-api-reference/mindlake.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.
