图形类型脚本库( 图形- ts)
TypeScript/ AssemblyScript 用于编写要部署到的子图映射库 图表。 。 。 .
使用量
关于如何创建子图的详细指南,请参见: 图 CLI 文件。 。 。 .
创建子图的一个步骤是写出将处理块链事件和将 将实体写入商店。 这些映射用TypeScript/AssemblyScript来写.
这个 graph-ts 库提供 API 访问 Graph 节点存储、块链数据、 智能
合同、IPFS数据、密码功能等等。 要用它,你只需要加一个
依赖它:
npm install --dev @graphprotocol/graph-ts # NPM
yarn add --dev @graphprotocol/graph-ts # Yarn
之后,您可以导入 store API 和您绘图中此库的其他特性 。 A 类
少数实例:
import { crypto, store } from '@graphprotocol/graph-ts'
// This is just an example event type generated by `graph-cli`
// from an Ethereum smart contract ABI
import { NameRegistered } from './types/abis/SomeContract'
// This is an example of an entity type generated from a
// subgraph's GraphQL schema
import { Domain } from './types/schema'
function handleNameRegistered(event: NameRegistered) {
// Example use of a crypto function
let id = crypto.keccak256(name).toHexString()
// Example use of the generated `Entry` class
let domain = new Domain()
domain.name = name
domain.owner = event.params.owner
domain.timeRegistered = event.block.timestamp
// Example use of the store API
store.set('Name', id, entity)
}
Assembly 脚本的辅助函数
参见 helper-functions.ts 文件输入
这个
用于一些有助于在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-子图
- https://github.com/graphprotocol/aragon-subgraph (中文(简体) )
- https://github.com/graphprotocol/dharma-subgraph 页面存档备份,存于互联网档案馆
许可证
版权所有 2018 Graph Protocol, Inc.和撰稿人.
图形类型脚本库在 麻省理工学院许可证 编辑 Apache 许可证,2.0版本。 。 。 .
除非适用法律要求或书面同意,否则根据许可证分发的软件 在 "AS IS " BASIS 上分发,不含任何种类的警报或条件,或明示或 隐含。 有关《公约》下许可和限制的具体语言,请参看《公约》 执照.