Consentimiento de cookies

Al continuar usando este sitio, aceptas el uso de cookies de acuerdo con nuestra Política de privacidad.

Docs
Buscar⌘ K
  • Inicio
  • Acerca de The Graph
  • Redes Admitidas
  • Protocol Contracts
  • Subgrafos
    • Comienzo Rapido
    • Graph Explorer
    • Querying
      • Developing
        • Introducción
        • Subgrafos
        • Creating
          • Starting Your Subgraph
          • Instalar The Graph CLI
          • Subgraph Manifest
          • The Graph QL Schema
          • Writing AssemblyScript Mappings
          • Advanced Subgraph Features
          • AssemblyScript API
            • Introducción
            • Referencias de API
            • Common Issues
            • Changelog
          • Marco de Unit Testing
        • Deployando
          • Publicando
            • Administrando
              • FAQ
            • Facturación
            • How-to Guides
              • Best Practices
                • Fair Use Policy
                • Upgrade Indexer
              • Corrientes secundarias
                • Token API
                  • AI Suite
                    • Indexación
                      • Recursos
                        Subgrafos > Developing > Creating > AssemblyScript API

                        2 minutos

                        The Graph TypeScript Library (graph-ts)

                        npm (scoped) Build Status

                        TypeScript/AssemblyScript library for writing subgraph mappings to be deployed to The Graph⁠.

                        Usage

                        For a detailed guide on how to create a subgraph, please see the Graph 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 graph-ts library provides APIs to access the Graph 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:

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

                        After that, you can import the store API and other features from this library in your mappings. A few examples:

                        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}

                        Helper Functions for AssemblyScript

                        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.

                        API

                        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/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⁠

                        License

                        Copyright © 2018 Graph Protocol, Inc. and contributors.

                        The Graph 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.

                        ⁠Editar en GitHub⁠

                        Advanced Subgraph FeaturesReferencias de API
                        En esta página
                        • Usage
                        • Helper Functions for AssemblyScript
                        • API
                        • License
                        The GraphEstadoTestnetRecursos de marcaForoSeguridadPolítica de privacidadTérminos de servicio
                        English
                        العربية
                        Čeština
                        Deutsch
                        Español
                        Français
                        हिन्दी
                        Italiano
                        日本語
                        मराठी
                        Português
                        Русский
                        Svenska
                        Türkçe
                        اردو
                        中文