Adam Fuller
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # NEAR indexing for Graph Node --- GIP: XXX Title: NEAR indexing for Graph Node Authors: Adam Fuller (adam@edgeandnode.com) Created: 2021-10-11 Updated: 2021-10-30 Stage: Draft Category: Subgraph API --- # Abstract This proposal describes the integration of NEAR into Graph Node as the first non-EVM chain. This involves the extraction of data from NEAR, the introduction of a new `kind` of subgraph data source (`near`), and the corresponding extension of the Subgraph API. # Motivation Realising the vision of The Graph means bringing the Graph Node's indexing capabilities to other Layer 1 chains. This will expand the protocol's addressable market and opportunities for future growth. NEAR is a smart contract platform, with a growing developer community. It is similar to Ethereum, but has some structural differences. It is therefore a good candidate to be the first new chain. # Prior Art This specification builds on the existing Graph Node implementation for Ethereum, the Multiblockchain refactor to remove Ethereum-specific components from the core of Graph Node, and the integration of the StreamingFast firehose into Graph Node. In terms of NEAR specific implementations, we refer to the [NEAR indexer framework](https://github.com/near/nearcore/tree/master/chain/indexer) and [derivatives](https://github.com/near/near-indexer-for-explorer), and the [Flux Capacitor](https://github.com/fluxprotocol/flux-capacitor/) (a custom indexer built on NEAR). # High Level Description NEAR data extraction will take place via a NEAR-specific Firehose implementation. This will enable ingestion of NEAR blocks into the Graph Node, which will be updated to support this new chain. Subgraph developers will be able to specify a new kind of dataSource (`near`) for their subgraphs, with specific triggers relevant to NEAR applications. A Near API will be added to `graph-ts`, for the selected trigger-types and useful NEAR data-types. # Detailed Specification ## Data extraction from NEAR into Graph Node NEAR data extraction will take place via a [Firehose implementation](https://github.com/streamingfast/near-dm-indexer) leveraging the [NEAR indexer framework](https://github.com/near/nearcore/tree/master/chain/indexer). This will enable ongoing indexing, as well as indexing past blocks. The NEAR Firehose gRPC endpoint will be consumed by Graph Node, which will implement a dedicated FirehoseBlockStream, NEAR specific types, and filtering for triggers. ### Operational requirements In order to index NEAR subgraphs, Indexers will therefore need to run the following: - NEAR Indexer Framework with Firehose instrumentation - NEAR Firehose Component(s) - Graph Node with Firehose endpoint configured ## NEAR subgraph developer experience - NEAR subgraphs will be identifiable by their dataSources, which will have `kind = near`. - NEAR dataSources may or may not refer to a specific NEAR contract (`source.account`). Contracts on NEAR are human-readable names (e.g. `mintbase.near`) - NEAR dataSources will support the following trigger types: - Block - invoked on every block - Receipt - invoked on every action receipt execution to a given account - Function Calls - invoked on specific [FunctionCalls](https://nomicon.io/RuntimeSpec/FunctionCall.html) to a given contract (as part of a Receipt Execution Outcome). _Receipt execution is when things **actually happen** on NEAR._ This does _not_ support potential other triggers: - Transactions: transactions on NEAR only represent an initiation of events - Non-function Actions: there are [actions beyond Function Calls](https://nomicon.io/RuntimeSpec/Actions.html), but Function Calls are the most interesting to developers ### Example Manifest definition ```yaml specVersion: 0.0.X schema: file: ./src/schema.graphql dataSources: - kind: near name: NearExample network: mainnet source: account: app.good-morning.near startBlock: 1 mapping: apiVersion: 0.0.X language: wasm/assemblyscript entities: - Thingy - Whatchamacall blockHandlers: - handler: handleNewBlock receiptHandlers: - handler: handleReceipt functionCallHandlers: - function: setPurpose handler: handleSetPurpose file: ./src/mapping.ts ``` At point of implementation each subgraph will only support one `kind` per subgraph.yaml (across datasources). ### NEAR AssemblyScript API Additional NEAR-specific types will need to be introduced into Graph Node and graph-ts to support the new dataSources. These will need to tie back to the data available from the FirehoseBlockStream. ```typescript class ExecutionOutcome { gasBurnt: u64, blockHash: Bytes, id: Bytes, logs: Array<string>, receiptIds: Array<Bytes>, tokensBurnt: BigInt, executorId: string, } class ActionReceipt { predecessorId: string, receiverId: string, id: CryptoHash, signerId: string, gasPrice: BigInt, outputDataReceivers: Array<DataReceiver>, inputDataIds: Array<CryptoHash>, actions: Array<ActionValue>, } class BlockHeader { height: u64, prevHeight: u64,// Always zero when version < V3 epochId: Bytes, nextEpochId: Bytes, chunksIncluded: u64, hash: Bytes, prevHash: Bytes, timestampNanosec: u64, randomValue: Bytes, gasPrice: BigInt, totalSupply: BigInt, latestProtocolVersion: u32, } class ChunkHeader { gasUsed: u64, gasLimit: u64, shardId: u64, chunkHash: Bytes, prevBlockHash: Bytes, balanceBurnt: BigInt, } class Block { author: string, header: BlockHeader, chunks: Array<ChunkHeader>, } class ReceiptWithOutcome { outcome: ExecutionOutcome, receipt: ActionReceipt, block: Block, } ``` [Reference](https://github.com/streamingfast/proto-near/blob/develop/sf/near/codec/v1/codec.proto) The entity passed to the handler will depend on the handler type: - Block handlers will receive a `Block` - Receipt handlers will receive a `ReceiptWithOutcome` #### Areas for further development: - The NEAR indexer framework does not map logs to their corresponding function call, which may present difficulties for subgraph developers if an execution outcome contains multiple function calls. - It is not simple to map back to a Transaction ID for a given receipt or execution outcome via the NEAR indexer framework, though this functionality has been requested. - The initial integration will not allow subgraph developers to [make Contract Calls to a NEAR RPC node](https://docs.near.org/docs/api/rpc/contracts#call-a-contract-function). This pattern can significantly slow down indexing performance, but will be reviewed based on user requirements. - The initial Firehose implementation does not populate a chain store, which means that the subgraph indexing status API will not have access to the chain head block, and will not be able to map block hashes in time travel queries to block numbers. ### GraphQL definition No changes are anticipated to the `schema.graphQL` # Backwards Compatibility This functionality is all additive. However we may make some revisions to the `subgraph.yaml` specification as we introduce this new functionality. # Dependencies - NEAR Firehose implementation - Multiblockchain refactor of Graph Node - Firehose Graph Node integration # Validation This implementation will be validated and iterated on with stakeholders from the NEAR ecosystem: - Core developers - Dapp developers # Rationale and Alternatives We considered a custom integration of the NEAR indexer framework with Graph Node, but determined that the Firehose would be a more robust & scalable approach. # Implementation - [NEAR in Graph Node](https://github.com/graphprotocol/graph-node/tree/master/chain/near) - [NEAR on StreamingFast](https://github.com/streamingfast/sf-near) - [NEAR Deepmind indexer](https://github.com/streamingfast/near-dm-indexer) - [NEARCore instrumentation](https://github.com/streamingfast/nearcore) - [NEAR Protobuf definitions](https://github.com/streamingfast/proto-near) # Copyright Waiver Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully