# TypeScript Quick-Start

* Demos on how to connect lake, create a table, encrypt data, and insert and query on encrypted data.
* You can check out [TypeScript API Reference](/mind-lake-sdk/typescript-api-reference.md) to view more advanced functions. &#x20;

##

## Preparation

If you need to configure TypeScript local environment, please visit our step-by-step tutorial for TypeScript:

{% embed url="<https://github.com/mind-network/mind-lake-sdk-typescript/blob/main/tutorial/README.md>" %}

## Source Code

```typescript
// import module module
import { MindLake } from 'mind-lake-sdk';

(async () => {
 const mindLake = await MindLake.getInstance("YOU OWN APP KEY"); // replace to your own appKey

 // connect to MindLake."5" is example of Goerli Testnet chainId
 const chainId = "5"
 const res1 = await mindLake.connect(chainId);
 if(res1.code !== 0) {
   return
 }

 // create a table
 const dataLake = mindLake.dataLake;
 const res2 = await dataLake.createTable("table_encrypted", [{columnName: 'id', type: DataType.int4, encrypt: true}, {columnName: 'name', type: DataType.text, encrypt: true}], ["id"]);
 if(res2.code !==0) {
   return
 }

 // encrypt data
 const cryptor = mindLake.cryptor;
 const res3 = await cryptor.encrypt(1, 'table_encrypted.id');
 const res4 = await cryptor.encrypt("Alice", 'table_encrypted.name');
 if(res3.code !==0 || res4.code !== 0) {
   return
 }

 // insert encrypted data
 const sql = `insert into table (id, name) values ('${res3.result}', '${res4.result}')`;
 const res5 = await dataLake.query(sql);
 console.log(`${sql} >>>`, JSON.stringify(res5));
 if(res5.code !== 0){
   return
 }

 //query encrypted data;
 const selectSql = `select * from table_encrypted`;
 const res6 = await dataLake.query(selectSql);
 if(res6.code === 0) {
  const columnList = res6.result.columnList;
  for (const row of res6.result.data) {
    for (const index in row) {
      const encryptData = row[index];
      const column = columnList[index];
      const decryptRes = await cryptor.decrypt(encryptData);
      console.log(`${column} decrypt data >>> `, decryptRes.result);
    }
  }
}
})();
```

## Execution Output:

```actionscript
insert into table_encrypt (id, name) values ('\xa00a0e01876d340832195bdf03ad5d18fe92355e62fdc823a650a3bbab064de2c55586be', '\x5c3a0f01fd8bfc4ef7ea3848f80e011d433b81e2e544975157556d75bad76c3b4865b0ea') >>> {"code":0,"result":null}
id decrypt data >>>  1
name decrypt data >>>  tom
```


---

# 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/get-started/typescript-quick-start.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.
