GQL
GQL simplifies the Arwave GraphQL operations to query blocks and transactions.
Instantiate
You can instantiate the GQL class with an endpoint url.
import { GQL } from "wao"
const gql = new GQL({ url: "https://arweave.net/graphql" }) // the default urlAR class auto-instantiates GQL internally.
import { AO } from "wao"
const ao = new AO()
const gql = ao.ar.gqlimport { AR } from "wao"
const ar = new AR()
const gql = ar.gqlTxs
Get latest transactions.
const txs = await gql.txs()asc
Get transactions in ascending order.
const txs = await gql.txs({ asc: true })first
Get the firxt X transactions.
const txs = await gql.txs({ first: 3 })after
Get transactions after a specific one to paginate. Pass a cursor.
const txs = await gql.txs({ first: 3 })
const txs2 = await gql.txs({ first: 3, after: txs[2].cursor })next
Easier pagination with next.
const { next, data: txs0_2 } = await gql.txs({ first: 3, next: true })
const { next: next2, data: txs3_5 } = await next()
const { next: next3, data: txs6_8 } = await next2()res.next will be null if there's no more transactions to paginate.
block
Get transactions within a block height range.
const txs = await gql.txs({ block: { min: 0, max: 10 } })or
const txs = await gql.txs({ block: [0, 10] })You can also specify only min or max.
by Transaction IDs
Get transactions by transaction ids.
const txs = await gql.txs({ id: TXID })or
const txs = await gql.txs({ ids: [ TXID1, TXID2, TXID3 ] })by Recipients
Get transactions by recipients.
const txs = await gql.txs({ recipient: ADDR })or
const txs = await gql.txs({ recipients: [ ADDR1, ADDR2, ADDR3 ] })by Owners
Get transactions by owners.
const txs = await gql.txs({ owner: ADDR })or
const txs = await gql.txs({ owners: [ ADDR1, ADDR2, ADDR3 ] })by Tags
Get transactions that match tags.
const txs = await gql.txs({ tags: { Name: "Bob", Age: "30" } })fields
Choose fields to be returned.
const txs = await gql.txs({ fields: ["id", "recipient"] })For nested objects,
const txs = await gql.txs({ fields: ["id", { owner: ["address", "key"] }] })You can use a hashmap to specify fields too.
const txs = await gql.txs({
fields: { id: true, { owner: { address: true, key: true } } }
})If you assign false, the other fields will be returned.
const txs = await gql.txs({
fields: { id: true, { block: { previous: false } } }
})For example, the above will exclude previous from block and return id, timestamp and height.
The entire available fields for transactions as in a graphql query are as follows.
const tx_fields = `{
id
anchor
signature
recipient
owner { address key }
fee { winston ar }
quantity { winston ar }
data { size type }
tags { name value }
block { id timestamp height previous }
parent { id }
bundledIn { id }
}`Blocks
Get latest blocks.
const blocks = await gql.blocks()asc
Get blocks in ascending order.
const blocks = await gql.blocks({ asc: true })first
Get the firxt X blocks.
const blocks = await gql.blocks({ first: 3 })after
Get blocks after a specific one to paginate. Pass a cursor.
const blocks = await gql.blocks({ first: 3 })
const blocks2 = await gql.blocks({ first: 3, after: blocks[2].cursor })by Block IDs
Get blocks by block ids.
const blocks = await gql.blocks({ id: BLCID })or
const blocks = await gql.blocks({ ids: [ BLKID1, BLKID2, BLKID3 ] })height
Get blocks within a block height range.
const blocks = await gql.blocks({ height: { min: 0, max: 10 } })or
const blocks = await gql.blocks({ height: [0, 10] })next
Easier pagination with next.
const { next, data: blocks0_2 } = await gql.blocks({ first: 3, next: true })
const { next: next2, data: blocks3_5 } = await next()
const { next: next3, data: blocks6_8 } = await next2()res.next will be null if there's no more blocks to paginate.
fields
const blocks = await gql.blocks({
fields: ["id", "timestamp", "height", "previous"]
})The entire available fields for blocks as in a graphql query are as follows.
const block_fields = `{ id timestamp height previous }`