GraphQL
Unionlabs provides a hosted indexing service for all connected chains, served at graphql.union.build. A GraphiQL Playground is also provided, which can be used to explore all available data. This guide goes through the most useful queries and types.
Although most HTTP clients can be used to query our API, we recommend URQL. Our GraphQL schema can
be downloaded using graphqurl
or graphql-inspector
:
This schema can be used by API clients and editors like VSCode to provide a better developer experience.
Concepts
The following definitions are used across the schema and documentation:
source
: The chain or rollup where the packet is sent from, often prefixed such assource_timestamp
orsource_transaction_hash
.destination
: The chain or roll-up that receives the packet.sender
: the contract or EOA that made the transfer.receiver
: the contract or EOA that received the transfer.
Queries
Below we have documented some common useful queries that are also leveraged in app.union.build. For all queries, Union
provides caches to increase performance. Use the syntax @cached(ttl: ${time_in_seconds})
to cache the query. The cache key, which is used
to map the query to the response, is computed by hashing:
- the GraphQL query.
- the GraphQL operation name.
- the GraphQL variables of the query.
Caching can dramatically improve performance. Always add at least @cached(ttl: 1)
to cache data between different windows, tabs, or users.
Transfers
Transfers facilitated by Union (either ucs01-relay-1
or ics20-1
) are queryable using v1_transfers.
It provides information on the sender, receiver, current stage of the transfer, and asset metadata.
To query for specific addresses, add the sender
and receiver
to the where clause:
Aggregate statistics about all transfers and packets are also available, such as the total amount of transfers and packets:
Packets
Packets, used in general message passing, can be tracked using v1_packets, similar to v1_transfers.
Traces
Both transfers and packets come with traces to track the progress of the message. There are four different trace types:
SEND_PACKET
LIGHTCLIENT_UPDATE
RECEIVE_PACKET
ACKNOWLEDGE_PACKET
For a specific transaction hash, you can obtain all traces of transfers and packets caused by this transaction (the initiating_transaction_hash
) by querying
The v1_traces.data
field is dependent on the type and may contain chain-specific information as well. The v1_transfers
and v1_packets
also have a relation to traces, to allow for all info of a specific transfer or packet.
Assets
Unionlabs provides a curated registry of different assets across different chains, including the bridged asset info for Union’s assets.
The assets can also be grouped and filtered by specific chains.
Pagination
Each model has a maximum number of rows that will be returned per query. Prefer using timestamp
or source_timestamp
as cursors when paginating.
Rate Limits
Rate limits are dynamically applied depending on traffic and abuse detection. If you require increased privilege to datasets and waived rate limits, contact us here
Next Steps
Go to the explorer and check out all data available. These endpoints can be used for data analytics, scraping, or used in frontends for rapid app development.