Get DAO Token Owners
Fetch all token owners of a DAO.
// Node doesn't implement fetch so we have to import it
import fetch from "node-fetch";
const SHYFT_API_KEY = "YOUR-KEY"
async function fetchGraphQL(query, variables = {}, name = "MyQuery") {
const result = await fetch(
`https://programs.shyft.to/v0/graphql/?api_key=${SHYFT_API_KEY}`,
{
method: "POST",
body: JSON.stringify({
query: query,
variables: variables,
operationName: name
})
}
);
return await result.json();
}
async function getRealmsForWallet(wallet) {
const query = `
query MyQuery {
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_TokenOwnerRecordV1(
where: {realm: {_eq: ${JSON.stringify(wallet)}}}
) {
governingTokenDepositAmount
governingTokenMint
governingTokenOwner
pubkey
}
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_TokenOwnerRecordV2(
where: {realm: {_eq: ${JSON.stringify(wallet)}}}
) {
governingTokenDepositAmount
governingTokenMint
governingTokenOwner
pubkey
}
}
`;
const { errors, data } = await fetchGraphQL(query);
if (errors) {
// handle those errors like a pro
console.error(errors);
}
// do something great with this precious data
return data;
}
//Get users for Grape DAO
const daos = await getRealmsForWallet("By2sVGZXwfQq6rAiAM3rNPJ9iQfb5e2QhnF4YjJ4Bip")
console.dir(daos, {depth: null})Last updated