TypeScript/AssemblyScript library for writing sublitegraph mappings to be deployed to The LiteGraph.
For a detailed guide on how to create a sublitegraph, please see the LiteGraph CLI docs.
One step of creating the subgraph is writing mappings that will process blockchain events and will write entities into the store. These mappings are written in TypeScript/AssemblyScript.
The litegraph-ts
library provides APIs to access the LiteGraph Node store,
blockchain data, smart contracts, data on IPFS, cryptographic functions
and more. To use it, all you have to do is add a dependency on it:
npm install --dev litegraph-ts # NPM
yarn add --dev litegraph-ts # Yarn
After that, you can import the store
API and other features from
this library in your mappings. A few examples:
import { store, crypto } from 'litegraph-ts'
// This is just an example event type generated by `litegraph-cli`
// from an Lite smart contract ABI
import { NameRegistered } from './types/abis/SomeContract'
// This is an example of an entity type generated from a
// sublitegraph's LiteGraphQL 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)
}
Refer to the helper-functions.ts
file in this repository for a few common functions that help build on top of the AssemblyScript library, such as byte array concatenation, among others.
Documentation on the API can be found here.
For examples of graph-ts
in use take a look at one of the following subgraphs:
- https://github.com/litegraph/lns-sublitegraph
- https://github.com/litegraph/decentraland-subgraph
- https://github.com/litegraph/adchain-subgraph
- https://github.com/litegraph/0x-subgraph
- https://github.com/litegraph/aragon-subgraph
- https://github.com/litegraph/dharma-subgraph
Copyright © 2018 Graph Protocol, Inc. and contributors.
The LiteGraph TypeScript library is dual-licensed under the MIT license and the Apache License, Version 2.0.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.