GraphQL API
Basement is a layer between your application and data stored on the blockchain. RPC Nodes such as Geth, Parity and Erigon are great on the execution-layer, but lack the features and reliability to support advanced applications displaying interactions with many smart contracts and wallets.
Our API helps you with faster data-access, use Basement to build your own indexer, or make use of one of our already indexed the primitives: such as marketplace sales or NFT transfers.
On-chain data querying​
Requests to Basement are accessed through a GraphQL API. GraphQL is a query language allowing developers to fetch a specific set of objects and fields of on-chain data.
This allows developers to query a large range of on-chain primitives, in just one simple request. Including Transactions, Logs and NFTs.
REST and RPC API drawbacks​
With a traditional RPC API or REST API, you are forced to make multiple requests to fetch the data you need. Let’s look at the example shown, where a Developer needs the metadata and sales of an NFT using OpenSea’s API.
POST
/asset/{contract}/{token_id}
→ Returns the NFT’s metadata, such as name and images
POST
/events?contract={contract}&token_id={token_id}
→ Returns interactions with this NFT, such as sales
This approach means making two requests for one use-case, exhausting rate-limits faster, waiting longer for responses, and N+1 problems if requests are dependent upon each other.
Basement’s GraphQL API​
With Basement’s GraphQL API, this can be reduced to a single request, with just the data you need for your use-case. Basement optimises any N+1 problems and dependency issues on the database side, to serve you a request faster than any REST API can.
Below is an example returning some metadata and sales across marketplaces.
query GetTokenSales($contract: String!, $id: String!) {
token(contract: $contract, id: $id) {
__typename
name
images {
thumbnail
}
sales {
price
marketPlace
}
}
}
To learn more about GraphQL queries head over to the official documentation
Query Playground​
Basement hosts a GraphiQL explorer, here you can experiment with queries, with interactive documentation.