Docs
搜索⌘ K
  • 主页
  • 关于 The Graph
  • 支持的网络
  • 协议合约
  • 子图
    • 子流
      • 代币 API
        • AI Suite
          • 索引
            • 资源
              子图 > 开发 > 创建 > 汇编脚本API

              3 分钟

              图形类型脚本库 (graph-ts)

              npm (scoped) Build Status

              要部署到 The Graph⁠写入子图的 TypeScript/AssemblyScript 库。

              使用方法

              关于如何创建子图的详细指南,请参阅 GraphCLI 文档⁠。

              创建子图的步骤是编写将处理区块链事件的映射,并将实体 写入存储。 这些映射都以 TypeScript/AssemblyScript 编写。

              graph-ts库提供 API,访问the Graph节点存储、区块链数据、智能 合约、IPFS数据、加密功能等数据。 若要使用它,您必须做的就是添加一个 依赖于它:

              1npm install --dev @graphprotocol/graph-ts # NPM2yarn add --dev @graph/graph-ts # Yarn

              然后,您可以在您的映射中导入这个库的 store API 和其他功能。 几个例子:

              1import { crypto, store } from '@graphprotocol/graph-ts'2// This is just an example event type generated by `graph-cli`3// from an Ethereum smart contract ABI4import { NameRegistered } from './types/abis/SomeContract'5// This is an example of an entity type generated from a6// subgraph's GraphQL schema7import { Domain } from './types/schema'89function handleNameRegistered(event: NameRegistered) {10  // Example use of a crypto function11  let id = crypto.keccak256(name).toHexString()1213  // Example use of the generated `Entry` class14  let domain = new Domain()15  domain.name = name16  domain.owner = event.params.owner17  domain.timeRegistered = event.block.timestamp1819  // Example use of the store API20  store.set('Name', id, entity)21}

              AssemblyScript 的辅助函数

              参考 这个⁠ 版本库用于一些共同的函数的助手函数,这些函数有助于在 AssemblyScript 库顶端上建构, 例如 字节数组会合等。

              API

              API 上的文档可以在这里找到 。

              对于所用的graph-ts的示例,请看下面的子图之一:

              • https://github.com/graphprotocol/ens-subgraph⁠
              • https://github.com/graphprotocol/decentraland-subgraph⁠
              • https://github.com/graphprotocol/adchain-subgraph⁠
              • https://github.com/graphprotocol/0x-subgraph⁠
              • https://github.com/graphprotocol/aragon-subgraph⁠
              • https://github.com/graphprotocol/dharma-subgraph⁠

              许可协议

              版权所有 © 2018 Graph协议、 公司和贡献者。

              GraphTypeScript 库是 MIT license⁠ 和 Apache License, 版本 2.0⁠的双向授权。

              除非适用法律要求或书面同意,否则根据许可证分发的软件 按“原样”分发,不附带任何明示或明示的保证或条件 暗指的。有关管理许可和限制的特定语言,请参阅许可证 许可证。

              ⁠在GitHub上编辑⁠

              高级子图功能API 参考
              在此页面上
              • 使用方法
              • AssemblyScript 的辅助函数
              • API
              • 许可协议
              The GraphStatusTestnetBrand AssetsForum安全Privacy PolicyTerms of Service