AllErc721.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. using Web3Unity.Scripts.Library.ETHEREUEM.EIP;
  3. public class AllErc721 : MonoBehaviour
  4. {
  5. public string[] nftContracts;
  6. public int amountOfTokenIdsToSearch;
  7. public int tokenIDStart; // set this as a starting point as needed
  8. string account;
  9. int balanceSearched;
  10. async void Start()
  11. {
  12. // This is the account taken from the user login scene
  13. account = PlayerPrefs.GetString("Account");
  14. // Searches through your listed contracts
  15. foreach (string contract in nftContracts)
  16. {
  17. int balance = await ERC721.BalanceOf(contract, account);
  18. Debug.Log("Balance of contract " + contract + ": " + balance);
  19. // if i is less than the selected amount of tokenIDs to search, keep searching
  20. for (int i = 1; i < amountOfTokenIdsToSearch; i++)
  21. {
  22. // if balanceSearched is less than the balance for each contract, keep searching
  23. if (balanceSearched < balance)
  24. {
  25. Debug.Log("Searching" + (tokenIDStart + i));
  26. string ownerOf = await ERC721.OwnerOf(contract, (tokenIDStart + i).ToString());
  27. // if token id id matches the account from login, print the tokenID and get the URI
  28. if (ownerOf == account)
  29. {
  30. string uri = await ERC721.URI(contract, (tokenIDStart + i).ToString());
  31. Debug.Log("TokenID: " + (tokenIDStart + i));
  32. Debug.Log("Token URI: " + uri);
  33. balanceSearched++;
  34. }
  35. }
  36. }
  37. }
  38. }
  39. }