Migrate from NEAR Lake framework
In this article you'll learn how to migrate your NEAR Lake Framework JavaScript indexer to Near QueryAPI, a fully managed solution to build indexer functions, extract on-chain data, store it in a database, and be able to query it using GraphQL endpoints.
Currently QueryAPI only supports JavaScript, so if your indexer code uses TypeScript, Python, or Rust, you'll have to re-write your indexing logic in JS before you can migrate it.
Basic migration
build/near-data-infrastructure/lake-framework/building-indexers/js-lake-indexer
Let's take a basic JS indexer built with NEAR Lake Framework as an example.
This indexer simply logs the Block height and the number of shards for each indexed block, using an indexer handler function handleStreamerMessage
.
Migrating this basic indexer to QueryAPI is simple. You only need to migrate the code from the handleStreamerMessage
function:
async function handleStreamerMessage(streamerMessage: types.StreamerMessage): Promise<void> {
console.log(`
Block #${streamerMessage.block.header.height}
Shards: ${streamerMessage.shards.length}
`);
}
Migrating to QueryAPI
- To start the migration process, create a new indexer using QueryAPI. You should see a similar interface like this:
- Since QueryAPI keeps a compatibility layer with Lake Framework, you don't need to change any references to
streamerMessage
in your indexer function. Just change the function definition to:
function handleStreamerMessage(streamerMessage) {
// ... Lake framework indexer code
}
- Next, add your migrated indexer function to the
getBlock(...)
method, and simply call your function passingblock.streamerMessage
as parameter:
async function getBlock(block: Block) {
// Add your code here
function handleStreamerMessage(streamerMessage) {
console.log(`
Block #${streamerMessage.block.header.height}
Shards: ${streamerMessage.shards.length}
`);
}
handleStreamerMessage(block.streamerMessage);
}