> For the complete documentation index, see [llms.txt](https://docs.chiliz.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chiliz.com/ko/gaebal/goseup/paen-token-jeonsong-chujjeok.md).

# Fan Token 전송 추적

Chiliz Chain에서 Fan Token 이동을 추적하는 것은 좋아하는 토큰의 활동을 모니터링하는 좋은 방법입니다. 잠재적인 대시보드의 빌딩 블록으로 활용하면 무엇이 인기 있고 무엇이 아닌지에 대한 인사이트를 제공하는 데이터를 정리할 수 있습니다.

Fan Token™ 이동을 추적할 때 빠르게 어려움에 직면합니다: 블록체인에서 직접 데이터를 읽는 것은 현재 상태("지갑 X의 잔액은 얼마인가?")에는 효율적이지만, 과거 데이터("지난 1년 동안 지갑 X와 관련된 모든 전송을 보여줘")에는 비효율적입니다.

이 문제를 해결하기 위해 서브그래프를 사용할 수 있습니다.

## 서브그래프에 대하여

서브그래프는 블록체인에서 데이터를 추출하고 처리하여 쉽게 쿼리할 수 있도록 저장하는 커스텀 API입니다.\
데이터가 필요할 때마다 블록체인에 수백만 개의 블록을 스캔하도록 요청하는 대신, 서브그래프는 특정 이벤트가 발생할 때 인덱싱하여 데이터베이스에 저장합니다.

Chiliz Chain은 업계 표준 인덱싱 프로토콜을 지원합니다. 프로젝트 요구에 맞는 공급자를 선택할 수 있습니다.

* [The Graph](https://thegraph.com/): 분산형 인덱싱의 업계 표준. 서브그래프를 분산형 인덱서 네트워크에 배포할 수 있습니다.
* [Goldsky](https://goldsky.com/): 고성능 호스팅 인덱싱 서비스. The Graph의 코드와 완전히 호환되며(동일한 코드를 그대로 사용할 수 있는 경우가 많음) 더 빠른 인덱싱 속도와 실시간 데이터 스트리밍 기능을 제공합니다.

두 도구 모두 동일한 개발 프레임워크를 사용하므로 이 페이지의 대부분 단계가 두 도구 모두에 적용됩니다.

PSG Fan Token의 전송을 추적하는 예시를 살펴보겠습니다...

## 0. 도구 선택

**The Graph**(분산형 네트워크) 또는 **Goldsky**(호스팅 인덱서)를 사용하여 Chiliz Chain에 서브그래프를 배포할 수 있습니다. 코드 구조는 동일하며 배포 명령만 다릅니다.

각자의 문서를 참고하세요.

{% embed url="<https://thegraph.com/docs/en/subgraphs/quick-start/>" %}

{% embed url="<https://docs.goldsky.com/subgraphs/deploying-subgraphs>" %}

## 1. 서브그래프 프로젝트 초기화

The Graph와 Goldsky 모두 그래프를 생성하는 CLI 기반 방법을 제공합니다.

{% hint style="info" %}
The Graph에는 [Subgraph Studio](https://thegraph.com/studio/)가 있으며 Web3로 연결한 후 인터페이스를 통해 서브그래프를 만들 수 있습니다.

Goldsky는 계정을 만들 때 [대시보드](https://app.goldsky.com/)를 제공하며 여기서 서브그래프를 만들 수 있습니다.
{% endhint %}

### Graph CLI 설치

로컬 머신에서 다음을 실행합니다.

```bash
npm install -g @graphprotocol/graph-cli
```

{% hint style="info" %}
The Graph의 CLI 도구를 사용하여 The Graph 분산형 서브그래프 또는 Goldsky 호스팅 서브그래프 모두에 대한 서브그래프를 만들 수 있습니다.

Goldsky에는 자체 CLI 도구가 있으며 Goldsky에 배포하려면 이 도구가 필요합니다(아래 참조).
{% endhint %}

### 서브그래프 초기화

서브그래프 페이지에서 직접 복사하여 특정 서브그래프 슬러그를 포함할 수 있습니다.

```bash
graph init --studio <SUBGRAPH_SLUG>
```

`--studio` 태그는 선택사항입니다.

PSG Fan Token 예시에서는 다음을 사용할 수 있습니다.

```bash
graph init chiliz-psg-fantoken-followup
```

서브그래프에 대한 정보를 입력하라는 메시지가 표시됩니다.

<figure><img src="/files/hIZVnSuCLVB2aJjiNUdh" alt=""><figcaption></figcaption></figure>

블록 탐색기에서 컨트랙트가 검증되어 있어야 하며, CLI가 자동으로 ABI를 가져와 서브그래프를 설정합니다. 기본 설정으로 각 이벤트에 대한 엔티티가 생성됩니다.

{% hint style="warning" %}
참고:

* PSG Fan Token처럼 컨트랙트가 프록시를 사용하는 경우 구현 컨트랙트 주소를 대신 사용하세요. 블록 탐색기의 컨트랙트 페이지에 있는 "읽기/쓰기 컨트랙트" 탭에서 확인할 수 있습니다. 예를 들어, [Chiliz Block Explorer에서 PSG Fan Token 컨트랙트](https://scan.chiliz.com/token/0xc2661815C69c2B3924D3dd0c2C1358A1E38A3105?tab=read_write_contract)를 참조하세요.
  * 프록시의 구현 컨트랙트 주소를 입력해야 했다면 프로젝트 설정 후 매니페스트 파일(`subgraph.yaml`)로 이동하여 컨트랙트 주소를 프록시 주소로 변경하세요.
* Start Block이 자동으로 가져오지 않는 경우 컨트랙트가 생성된 블록 번호를 수동으로 입력할 수 있습니다. 블록 탐색기에서 확인할 수 있습니다.
  {% endhint %}

{% hint style="info" %}
서브그래프를 변경할 때 주로 세 가지 파일을 작업합니다.

* 매니페스트(`subgraph.yaml`): 서브그래프가 인덱싱할 데이터 소스를 정의합니다.
* 스키마(`schema.graphql`): 서브그래프에서 검색할 데이터를 정의합니다.
* AssemblyScript 매핑(`mapping.ts`): 데이터 소스의 데이터를 스키마에 정의된 엔티티로 변환합니다.
  {% endhint %}

`subgraph.yaml`을 열고 매니페스트 파일이 올바른 네트워크를 가리키는지 확인합니다.

```yaml
dataSources:
  - kind: ethereum
    name: FanToken
    network: chiliz  # Mainnet은 'chiliz', Spicy는 chiliz-testnet 사용
    source:
      address: "0x..." 
      abi: FanToken
```

### 서브그래프 컴파일

마지막으로 오류가 없는지 확인하기 위해 서브그래프를 컴파일합니다.

```bash
graph codegen && graph build
```

## 2. 배포 및 게시

서브그래프가 빌드되면 배포할 공급자를 선택합니다.

{% columns %}
{% column %}
**The Graph**

1. [Subgraph Studio](https://thegraph.com/studio/)에 연결하고 서브그래프를 만든 후 배포 키를 복사합니다.
2. CLI를 통해 인증합니다:\
   `graph auth --studio <DEPLOY_KEY>`
3. 서브그래프를 Subgraph Studio에 배포합니다:\
   `graph deploy --studio <SUBGRAPH_SLUG>`
4. Studio로 이동하여 서브그래프를 열고 "게시"를 클릭하여 서브그래프를 분산형 네트워크에 발행합니다.\
   지갑을 통해 트랜잭션을 실행하여 서브그래프를 Arbitrum One 네트워크에 NFT로 게시합니다.
   {% endcolumn %}

{% column %}
**Goldsky**

1. [Goldsky](https://app.goldsky.com/)로 이동하여 "프로젝트 설정"에서 API 키를 만들고 CLI를 통해 로그인합니다.
2. `goldsky` 명령을 설치합니다:\
   `curl https://goldsky.com | sh`\
   그런 다음 CLI를 통해 인증합니다:\
   `goldsky login`
3. 서브그래프를 Goldsky에 업로드합니다:\
   `goldsky subgraph deploy / --path`

Goldsky 서브그래프는 배포 후 즉시 활성화됩니다. 추가 게시 단계가 필요하지 않습니다.
{% endcolumn %}
{% endcolumns %}

{% hint style="info" %}
버전 레이블을 입력하라는 메시지가 표시됩니다. `v0.0.1`과 같이 입력할 수 있지만 형식은 자유롭게 선택할 수 있습니다. 완료되면 Studio 페이지에서 서브그래프가 동기화를 시작하는 것을 확인할 수 있습니다.
{% endhint %}

{% hint style="info" %}
서브그래프가 Chiliz Chain의 데이터를 인덱싱하더라도 The Graph의 스마트 컨트랙트는 모두 [Arbitrum One](https://arbitrum.io/arbitrum-101)에 있습니다.
{% endhint %}

## 3. 서브그래프 쿼리

축하합니다! 이제 선택한 서비스의 대시보드에서 찾을 수 있는 서브그래프의 쿼리 URL에 GraphQL 쿼리를 전달하여 쿼리를 시작할 수 있습니다.

예시:

{% columns %}
{% column %}
**The Graph**

`https://gateway-arbitrum.network.thegraph.com/api/[APIKEY]/subgraphs/id/[ID]`
{% endcolumn %}

{% column %}
**Goldsky**

`https://api.goldsky.com/api/public/project_[KEY]/subgraphs/[SLUG]/1.0.0/gn`
{% endcolumn %}
{% endcolumns %}

이제 세부사항을 입력하여 이 엔드포인트에 GraphQL 쿼리를 전송하기 시작하면 됩니다.

## 부록

### 샘플 쿼리

이 쿼리는 PSG Fan Token의 모든 트랜잭션을 보여줍니다.

```typescript
const axios = require('axios');

// GraphQL 쿼리 (두 공급자 모두 동일)
const graphqlQuery = `{
  transfers {
    from
    to
    value
    transactionHash
  }
}`;

// 공급자에 따라 올바른 URL 형식을 선택합니다:
// const queryUrl = 'https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/[id]'
// const queryUrl = 'https://api.goldsky.com/api/public/project_[key]/subgraphs/[slug]/1.0.0/gn';

const graphQLRequest = {
  method: 'post',
  url: queryUrl,
  data: {
    query: graphqlQuery,
  },
};

// GraphQL 쿼리 전송
axios(graphQLRequest)
  .then((response) => {
    // 여기서 응답을 처리합니다
    const data = response.data.data
    console.log(data)

  })
  .catch((error) => {
    // 오류 처리
    console.error(error);
  });
```

### 샘플 코드

```json
{
  "data": {
    "transfers": [
      {
        "from": "0x26a3e78fa4d2cbebf6b59b2f84b8fb7c61b52d28",
        "to": "0xdca23d02923d01779fb22959bd2575d64eab4535",
        "value": "1500",
        "transactionHash": "0x000309e9cd3f550e8965381bbd83a35c5cee18f26c33a357f9dbb57450d594ea"
      },
//      ...
  }
}
```

## 추가 리소스

GraphQL로 서브그래프에서 데이터를 쿼리하는 방법에 대한 자세한 정보:

{% embed url="<https://thegraph.com/docs/en/subgraphs/querying/best-practices/>" %}


---

# 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://docs.chiliz.com/ko/gaebal/goseup/paen-token-jeonsong-chujjeok.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.
