# Get Started

{% hint style="info" %}
MetaID-TS-SDK 源代码已发布在 Github 上，相关 API 和示例代码请以 Github 最新页面为准

<https://github.com/metaid-developers/metaid>
{% endhint %}

## Introduction

MetaID SDK提供了一套规范标准和方法工具，用来生成和处理遵循MetaID协议的底层区块链数据(这里具体指符合UTXO标准的链， 目前支持BTC链) 。

MetaID SDK的设计目标是提供一个相对统一且高效的方法，大大简化了web3服务的整合，免去了开发者需与多种协议打交道以及数据上链时需自行构建复杂UTXO交易的需求，节省时间且减小了面临兼容性问题的风险。

基于MetaID SDK的简洁性，兼容性，可扩展性，高效性， 传统应用开发者可以快速开发并部署一个运行在UTXO链上的Dapp应用。

## Core Concepts

MetaID SDK有两个核心概念：连接器（connector）和实体（entity）。

连接器用于身份信息的认证和管理，作为用户在区块链上发布数据的基础。

"实体"是在应用层中使用的术语。它用于管理某种特定数据类型的资源。从编程的角度来看，当你创建一个新的实体实例时，你可以访问其属性，并利用它所提供的一系列可执行链上数据存储和修改的方法。你可以将每一类Entity理解为分别对应于MetaID Specification中的PATH部分。

## PIN索引规则

### 通用

#### 识别Flag

* **metaid**

#### 大小写规则

* 大小写不敏感，索引器可以全部转为小写保存。

### Operation

* **init** 类型 PIN 所在的交易的 `txid` 为一个 `metaid` 的 `roottxid`。
* **init**、**create** 遵循先到先得原则。
* 同一区块内 **init**、**create** 不区分先后顺序，索引器应先处理 **init** 类型 PIN，再处理其他类型 PIN。
  * 先处理 **init** 是为了得到 `roottxid/metaid`。

### Path

* 对于相同的 `path`，所有 **init** 和 **create** 的 PIN 是看最旧的，只有 **modify/revoke** 才是看最新的。
* **modify/revoke** 必须对已入块的 PIN 操作，即 **modify/revoke** 只对已经入块的 PIN 有效，即使同区块也是无效的。
* 非 **init-PIN** 的 `path` 一定是在以下 `path` 内，一个 `metaid` 默认存在这五个一级 `path`：
  * `/info`
  * `/file`
  * `/protocols`
  * `/nft`
  * `/ft`

#### Path 规则

* 以 `/file`、`/protocols`、`/nft`、`/ft` 开始的 `path` 应该是全路径的，如： `/protocols/simplebuzz/file/my-pfp.jpg`。

## Installation

#### Method 1: 使用 yarn 或 npm

```bash
// 使用 yarn
yarn add @metaid/metaid 

// 使用 npm
npm install --save @metaid/metaid
```

#### Method 2: 以 src 方式引入到你的原生 JS 项目中

该方法会把 npm 版本的包转换成浏览器能运行的包，无需打包工具（如 webpack）。

1. 初始化一个本地项目

```bash
mkdir generate-metaid-bundle && cd generate-metaid-bundle/ 
yarn init 
// 或者
npm init
```

2. 安装 SDK：

```bash
npm install --save @metaid/metaid
// 或者
yarn add @metaid/metaid
```

3. 写一个 `main.js` 文件，只需要两行代码：

```javascript
var metaidSDK = require('@metaid/metaid')
window.metaidSDK = metaidSDK
```

4. 使用 npm 全局安装 browserify：

```bash
npm install -g browserify
// 或者 
yarn global add browserify
```

5. 安装完成以后，执行命令：

```bash
browserify main.js -o bundle.js
```

命令运行完成以后，会生成一个 `bundle.js` 文件。现在我们就可以把这个文件和 HTML 代码放在一起，通过 `<script>` 标签导入了：

```html
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <script src="bundle.js"></script>
    </head>
    <body>
        <div class="app">
             <!-- HTML tag of your page -->
        </div>
        <script>
            // JS code
        </script>
    </body>
</html>
```


---

# 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.metaid.io/zh/metaid-sdk/get-started.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.
