Skip to main content

SDK

The Basement SDK has sensible defaults and flexibility to allow you to get the data you want efficiently and effortlessly.

Installation

Basement SDK is available as an npm package

yarn add @basementdev/sdk

Getting Started

Here's an example of a basic query using the SDK:

import { BasementSDK } from "@basementdev/sdk";

const sdk = new BasementSDK();

const data = await sdk.address({
address: "vitalik.eth",
include: { profile: true, tokens: true },
});

Instantiating

When initialising the SDK, we can optionally pass an object, as shown in the snippet below:

import { BasementSDK } from "@basementdev/sdk";

const sdk = new BasementSDK({
apiKey: process.env.API_KEY,
endpoint: "https://api.basement.dev/v2/graphql",
});
NameTypeDescription
apiKeystringAPI Key - limited to 30 requests per minute without an API key. Once the limit is exceeded, an API key will be required
endpointstringAPI Endpoint - defaults to https://api.basement.dev/v2/graphql

Defaults

All the methods return the minimum amount of data required for the query to be useful, which is opinionated. Thus, if more data is needed, an include object is available on every method to have more granularity when building the query, and every property within the object is false as its default value.

Methods

token

Queries information about a specific token

Example usage

const token = await sdk.token({
contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
tokenId: "660",
media: true,
sales: true,
include: {
owner: true,
},
});

Parameters

NameTypeDescription
contractstringToken's contract hex-address or ENS name.
tokenIdstringThe token ID within the contract.
include.mediaboolIf true, the media attached to the token, like the image and animation will be included.
include.attributesboolIf true, the attributes of the token will be included.
include.tokenUriboolIf true, the tokenUri will be included, which is directly called from the contract and given as is, in JSON format.
include.salesobject | boolIf true, sale data will be included. This includes information like the price at which previous sales happened and on which marketplace.
include.sales.makerobject | boolIf true, it will include the maker's address
include.sales.maker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.sales.takerobject | boolIf true, it will include the taker's address
include.sales.taker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.mintTransactionobject | boolIf true, the information regarding the token's mint will be included. This includes information like the mint transaction and mint price.
include.mintTransaction.logsboolIf true, it will include the logs that happened within the transaction.
include.mintTransaction.fromobject | boolIf true, it will include the sender's address that initiated this transaction.
include.mintTransaction.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.mintTransaction.toobject | boolIf true, it will include the address the transaction was sent to. This can be another wallet, a contract, or null in the case of a contract creation.
include.mintTransaction.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.ownerobject | boolIf true, only the owner's address will be included. This includes information like the mint transaction and mint price.
include.owner.profileboolIf true, the profile information will be included, if available.
include.owner.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.

Returns:

Promise<TokenQuery["token"]> - follows the structure of Erc721Token

tokens

Query tokens that satisfy the given filter(s)

Example usage

const data = await sdk.tokens({
filter: { ownerAddresses: ["vitalik.eth"] },
include: { owner: true },
});

Parameters

NameTypeDescription
filter.ownerAddressesstring[]Filter tokens that satisfy the given owner addresses.
limitnumberMaximum number of tokens to return.
afterstringCursor used for pagination. To go the next page, provide the given cursor from the response, if available.
include.totalCountboolIf true, it will include the total count. It's capped at 10,000 for performance reasons.
include.mediaboolIf true, the media attached to the token, like the image and animation will be included.
include.attributesboolIf true, the attributes of the token will be included.
include.tokenUriboolIf true, the tokenUri will be included, which is directly called from the contract and given as is, in JSON format.
include.salesobject | boolIf true, sale data will be included. This includes information like the price at which previous sales happened and on which marketplace.
include.sales.makerobject | boolIf true, it will include the maker's address
include.sales.maker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.sales.takerobject | boolIf true, it will include the taker's address
include.sales.taker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.mintTransactionobject | boolIf true, the information regarding the token's mint will be included. This includes information like the mint transaction and mint price.
include.mintTransaction.logsboolIf true, it will include the logs that happened within the transaction.
include.mintTransaction.fromobject | boolIf true, it will include the sender's address that initiated this transaction.
include.mintTransaction.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.mintTransaction.toobject | boolIf true, it will include the address the transaction was sent to. This can be another wallet, a contract, or null in the case of a contract creation.
include.mintTransaction.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.ownerobject | boolIf true, only the owner's address will be included. This includes information like the mint transaction and mint price.
include.owner.profileboolIf true, the profile information will be included, if available.
include.owner.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.

Returns

Promise<TokensQuery["tokens"]> - follows the structure of TokensPage

address

Queries information about an address

Example usage

const data = await sdk.address({
address: "vitalik.eth",
include: { profile: true, tokens: { limit: 5 } },
});

Parameters

NameTypeDescription
addressstringhex-address or ENS address
include.tokens.limitnumberMaximum number of tokens to return.
include.profileboolIf true, the profile information will be included, if available.
include.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.tokensobject | boolIf true, it will include basic data like name and description of the token.
include.tokens.mediaboolIf true, the media attached to the token, like the image and animation will be included.
include.tokens.attributesboolIf true, the attributes of the token will be included.
include.tokens.tokenUriboolIf true, the tokenUri will be included, which is directly called from the contract and given as is, in JSON format.
include.tokens.salesobject | boolIf true, sale data will be included. This includes information like the price at which previous sales happened and on which marketplace.
include.tokens.sales.makerobject | boolIf true, it will include the maker's address
include.tokens.sales.maker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.tokens.sales.takerobject | boolIf true, it will include the taker's address
include.tokens.sales.taker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.tokens.mintTransactionobject | boolIf true, the information regarding the token's mint will be included. This includes information like the mint transaction and mint price.
include.tokens.mintTransaction.logsboolIf true, it will include the logs that happened within the transaction.
include.tokens.mintTransaction.fromobject | boolIf true, it will include the sender's address that initiated this transaction.
include.tokens.mintTransaction.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.tokens.mintTransaction.toobject | boolIf true, it will include the address the transaction was sent to. This can be another wallet, a contract, or null in the case of a contract creation.
include.tokens.mintTransaction.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.

Returns

Promise<AddressQuery["address"]> - follows the structure of Address

transaction

Queries information about a transaction

Example usage

const tx = await sdk.transaction({
hash: "0xcdcc49079b7622c9527e9bd50314dda94ac4e3da5e0378d1ed1c41b1a442f531",
include: { logs: true, from: true, to: true },
});

Parameters

NameTypeDescription
hashstringTransaction hash
include.fromobject | boolIf true, it will include the sender's address that initiated this transaction.
include.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.toobject | boolIf true, it will include the address the transaction was sent to. This can be another wallet, a contract, or null in the case of a contract creation.
include.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.logsboolIf true, it will include the logs that happened within the transaction.

Returns

Promise<TransactionQuery["transaction"]> - follows the structure of Transaction

transactions

Query transactions that satisfy the given filter(s)

Example usage

const data = await sdk.transactions({
filter: { toAddresses: ["vitalik.eth"] },
include: { totalCount: true, from: true, to: true },
});

Parameters

NameTypeDescription
filter.methodIdsstring[]A list of methodIds as specified in the first 4 bytes of calldata. Note: this field is not verified to be a valid call. Addresses may send transactions with arbitrary data.
filter.toAddressesstring[]A list of addresses to whom a transaction was sent. Add null to include contract creation transactions. Ignored when empty.
filter.blockNumbersnumber[]A list of block numbers to include transactions from.
filter.fromAddressesstring[]A list of addresses who initiated transactions. Ignored when empty.
include.totalCountboolIf true, it will include the total count. It's capped at 10,000 for performance reasons.
include.fromobject | boolIf true, it will include the sender's address that initiated this transaction.
include.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.toobject | boolIf true, it will include the address the transaction was sent to. This can be another wallet, a contract, or null in the case of a contract creation.
include.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.logsboolIf true, it will include the logs that happened within the transaction.

Returns

Promise<TransactionsQuery["transactions"]> - follows the structure of TransactionPage

transactionLogs

Query transaction logs that satisfy the given filter(s)

Example usage

const data = await sdk.transactionLogs({
filter: { includeRemoved: true, topics: [[]] },
include: {
totalCount: true,
address: true,
transaction: { from: true, to: true },
},
});

Parameters

NameTypeDescription
filter.includeRemovedboolIf true, it will filter logs which were removed during a block reorg.
filter.topicsstring[][]A list of topics to search for. See this section for more details.
filter.addressesstring[]A list of contract addresses from which this log was emitted. Ignored when empty.
filter.blockNumbersnumber[]A list of block numbers to include transaction logs from
filter.blockHashesstring[]A list of block hashes to include transaction logs from
filter.transaction.fromAddressesstring[]A list of block numbers to include transaction logs from
filter.transaction.toAddressesstring[]A list of addresses to whom a transaction was sent. Add null to include contract creation transactions. Ignored when empty.
include.totalCountboolIf true, it will include the total count. It's capped at 10,000 for performance reasons.
include.blockHashboolIf true, it will include the block hash
include.addressobject | boolIf true, it will include include the address of the contract which emitted this log.
include.address.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.transaction.fromobject | boolIf true, it will include the sender's address that initiated this transaction.
include.transaction.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.transaction.toobject | boolIf true, it will include the address the transaction was sent to. This can be another wallet, a contract, or null in the case of a contract creation.
include.transaction.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.

Returns

Promise<TransactionLogsQuery["transactionLogs"]> - follows the structure of TransactionLogPage

nonFungibleTokenRefresh

Refreshes metadata of a specific token

Example usage

const data = await sdk.nonFungibleTokenRefresh({
contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
tokenId: "660",
});

Parameters

NameTypeDefaultDescription
contractstringThe contract's hex-address or ENS name.
tokenIdstringThe token ID within the contract.

Returns

Promise<string | null>

erc721Transfers

Query ERC721 transfers that satisfy the given filter(s)

Example usage

const data = await sdk.erc721Transfers({
filter: {
exclude: [
ExcludeTransferFilter.Airdrop,
ExcludeTransferFilter.ZeroEthTransfer,
],
},
include: {
totalCount: true,
contract: true,
from: true,
to: true,
sale: {
maker: { reverseProfile: true },
taker: { reverseProfile: false },
},
token: ,
transaction: true,
},
});

Parameters

NameTypeDescription
filter.blockNumbersnumber[]A list of block numbers to include transfers from.
filter.blockHashesstring[]A list of block hashes to include transfers from
filter.contractAddressesstring[]A list of contract addresses to include transfers from.
filter.fromAddressesstring[]A list of addresses who sent the NFT.
filter.toAddressesstring[]A list of addresses who received the NFT.
filter.tokenIdsstring[]Token IDs to include transfers from.
filter.excludeExcludeTransferFilter[]Categories to exclude transfers from.
limitnumberMaximum number of token transfers to return.
include.totalCountboolIf true, it will include the total count. It's capped at 10,000 for performance reasons.
include.contractboolIf true, it will include the address containing this token's contract code
include.blockHashboolIf true, it will include the block hash
include.contract.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.fromobject | boolIf true, the address sending this token, when this contains the null address this token was minted during this transfer.
include.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.toobject | boolIf true, it will include the address receiving this token, when this contains the null address this token was burned during this transfer
include.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.transaction.fromobject | boolIf true, it will include the sender's address that initiated this transaction.
include.transaction.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.transaction.toobject | boolIf true, it will include the address the transaction was sent to. This can be another wallet, a contract, or null in the case of a contract creation.
include.transaction.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.transaction.logsboolIf true, it will include the logs that happened within the transaction.
include.transaction.eventsboolIf true, it will include the events that happened within the transaction.
include.saleobject | boolIf true, it will include the sale log found to be associated with this transfer
include.sale.makerobject | boolIf true, it will include the maker's address
include.sale.maker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.sale.takerobject | boolIf true, it will include the taker's address
include.sale.taker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.tokenobject | boolIf true, it will include basic data like name and description of the token.
include.token.mediaboolIf true, the media attached to the token, like the image and animation will be included.
include.token.attributesboolIf true, the attributes of the token will be included.
include.token.tokenUriboolIf true, the tokenUri will be included, which is directly called from the contract and given as is, in JSON format.
include.token.salesobject | boolIf true, sale data will be included. This includes information like the price at which previous sales happened and on which marketplace.
include.token.sales.makerobject | boolIf true, it will include the maker's address
include.token.sales.maker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.token.sales.takerobject | boolIf true, it will include the taker's address
include.token.sales.taker.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.token.mintTransactionobject | boolIf true, the information regarding the token's mint will be included. This includes information like the mint transaction and mint price.
include.token.mintTransaction.logsboolIf true, it will include the logs that happened within the transaction.
include.token.mintTransaction.fromobject | boolIf true, it will include the sender's address that initiated this transaction.
include.token.mintTransaction.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.token.mintTransaction.toobject | boolIf true, it will include the address the transaction was sent to. This can be another wallet, a contract, or null in the case of a contract creation.
include.token.mintTransaction.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.

Returns

Promise<Erc721TransfersQuery["erc721Transfers"]> - follows the structure of Erc721TransferPage

erc20Transfers

Query ERC20 transfers that satisfy the given filter(s)

Example usage

const data = await sdk.erc20Transfers({
filter: {
exclude: [ExcludeTransferFilter.Airdrop],
},
include: {
totalCount: true,
contract: true,
from: true,
to: true,
transaction: true,
},
});

Parameters

NameTypeDescription
filter.blockNumbersnumber[]A list of block numbers to include transfers from.
filter.contractAddressesstring[]A list of contract addresses to include transfers from.
filter.fromAddressesstring[]A list of addresses who sent the NFT.
filter.toAddressesstring[]A list of addresses who received the NFT.
filter.tokenIdsstring[]Token IDs to include transfers from.
filter.excludeExcludeTransferFilter[]Categories to exclude transfers from.
limitnumberMaximum number of token transfers to return.
include.totalCountboolIf true, it will include the total count. It's capped at 10,000 for performance reasons.
include.fromobject | boolIf true, the address sending this token, when this contains the null address this token was minted during this transfer.
include.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.toobject | boolIf true, it will include the address receiving this token, when this contains the null address this token was burned during this transfer
include.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.transaction.fromobject | boolIf true, it will include the sender's address that initiated this transaction.
include.transaction.from.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.transaction.toobject | boolIf true, it will include the address the transaction was sent to. This can be another wallet, a contract, or null in the case of a contract creation.
include.transaction.to.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.
include.transaction.logsboolIf true, it will include the logs that happened within the transaction.
include.transaction.eventsboolIf true, it will include the events that happened within the transaction.

Returns

Promise<Erc20TransfersQuery["erc20Transfers"]>

erc20Balances

Query ERC20 balances from a given address

Example usage

const data = await sdk.erc20Transfers({
filter: { ownerAddress: "vitalik.eth" },
include: { owner: { profile: true, reverseProfile: true } },
});

Parameters

NameTypeDescription
filter.ownerAddressstringOwner address (ENS or HEX address).
include.ownerobject | boolIf true, only the owner's address will be included. This includes information like the mint transaction and mint price.
include.owner.profileboolIf true, the profile information will be included, if available.
include.owner.reverseProfileboolIf true, the reverse resolution of the ENS (ENS docs) profile information will be included, if available.

Returns

Promise<Erc20BalancesQuery["erc20Balances"]>

request

Gives flexibility to execute any request within the context of the Basement API.

Example usage

const data = await sdk.request(
gql`
query address($address: String!) {
address(address: $address) {
address
}
}
`,
{ address: "vitalik.eth" }
);