This will return the asset information for a specific group provided (i.e Collection). This can return compressed or standard NFTs.
const url = "https://mainnet.helius-rpc.com/?api-key=<api-key>"
const getAssetsByGroup = async () => {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 'my-id',
method: 'getAssetsByGroup',
params: {
groupKey: 'collection',
groupValue: 'J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w',
page: 1, // Starts at 1
limit: 1000,
},
}),
});
const { result } = await response.json();
console.log("Assets by Group: ", result.items);
};
getAssetsByGroup();
const url = "https://mainnet.helius-rpc.com/?api-key=<api-key>"
const getAssetsByGroup = async () => {
console.time("getAssetsByGroup"); // Start the timer
let page = 1;
let assetList = [];
while (page) {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: "my-id",
method: "getAssetsByGroup",
params: {
groupKey: "collection",
groupValue: "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w",
page: page,
limit: 1000,
},
}),
});
const { result } = await response.json();
assetList.push(...result.items);
if (result.total !== 1000) {
page = false;
} else {
page++;
}
}
const resultData = {
totalResults: assetList.length,
results: assetList,
};
console.log("Mad Lads Assets: ", resultData);
};
getAssetsByGroup();