hashgraph / hedera-sdk-js

Hedera™ Hashgraph SDK for JavaScript/TypeScript
https://docs.hedera.com/guides/docs/sdks
Apache License 2.0
253 stars 131 forks source link

NO_REMAINING_AUTOMATIC_ASSOCIATIONS #2356

Closed AdrianKBL closed 1 week ago

AdrianKBL commented 1 week ago

Description

For the Account Id 0.0.1704837 , the MirrorNode is returning that has 2 remainingAutomaticAssociations left, however, whenever this account tries to get an NFT (Without having the Token Id associated) It ends with the error from the SDK NO_REMAINING_AUTOMATIC_ASSOCIATIONS

Steps to reproduce

const accountId = "1704837";
const baseUrl = "https://mainnet-public.mirrornode.hedera.com/";
const tokensUrl = `${baseUrl}/api/v1/accounts/${accountId}/tokens?limit=100&order=desc`;
const accountUrl = `${baseUrl}/api/v1/accounts/${accountId}`;

async function fetchTokens(url) {
  let tokenAccount = [];
  let nextUrl = url;

  while (nextUrl) {
    const response = await fetch(nextUrl);
    const data = await response.json();
    tokenAccount = tokenAccount.concat(data.tokens);
    nextUrl = data.links.next ? baseUrl + data.links.next : null;
  }

  return tokenAccount;
}

async function getAccountInfo(url) {
  const response = await fetch(url);
  const data = await response.json();
  return data;
}

async function main() {
  // Fetch tokens
  const tokens = await fetchTokens(tokensUrl);

  // Count tokens with automatic_association == true
  const automaticAssociationCount = tokens.filter(token => token.automatic_association).length;

  console.log(`Number of tokens with automatic association: ${automaticAssociationCount}`);

  // Fetch account information
  const accountInfo = await getAccountInfo(accountUrl);

  console.log(`Max automatic token associations: ${accountInfo.max_automatic_token_associations}`);
}

main();

Output: Number of tokens with automatic association: 7 Max automatic token associations: 9

I should be able to automatically associate 2 more tokens, but the network does not allow it and transactions fail with an error. image

Additional context

No response

Hedera network

mainnet

Version

v2.45.0

Operating system

macOS

SimiHunjan commented 1 week ago

@steven-sheehy could there be a discrepancy between what the mirror node is returning vs. what the node software has in state for this account? If the node software is returning there are no automatic token association slots available then that should be true for the mirror node?

SimiHunjan commented 1 week ago

@AdrianKBL the mirror node team noted they don't track remaining automatic token association slots and linked this issue where they state that https://github.com/hashgraph/hedera-mirror-node/issues/7399

SimiHunjan commented 1 week ago

@AdrianKBL the next steps for the mirror node to support this in the future is for someone in the community to champion the HIP

SimiHunjan commented 1 week ago

Closing this issue as it is unrelated to the SDK.