Getting token address restrictions attached to an account

Get the list of token address restrictions.

Prerequisites

Method #01: Using the SDK

// replace with address
const rawAddress = 'BXRBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = Address.createFromRawAddress(rawAddress);
// replace with token id
const tokenIdHex = '634a8ac3fc2b65b3';
const tokenId = new TokenId(tokenIdHex);
// replace with node endpoint
const nodeUrl = 'NODE_URL';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const restrictionHttp = repositoryFactory.createRestrictionTokenRepository();

const criteria = { tokenId, targetAddress: address };
restrictionHttp.search(criteria).subscribe(
  (tokenAddressRestrictions) => {
    if (tokenAddressRestrictions.data.length > 0) {
      tokenAddressRestrictions.data.forEach((tokenRestriction) => {
        tokenRestriction.restrictions.forEach(
          (value: TokenAddressRestrictionItem) => {
            console.log('\n', value.key, value.restrictionValue);
          },
        );
      });
    } else {
      console.log(
        '\n The address does not have token address restrictions assigned.',
      );
    }
  },
  (err) => console.log(err),
);
// replace with address
const rawAddress = 'BXRBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = bitxor_sdk_1.Address.createFromRawAddress(rawAddress);
// replace with token id
const tokenIdHex = '634a8ac3fc2b65b3';
const tokenId = new bitxor_sdk_1.TokenId(tokenIdHex);
// replace with node endpoint
const nodeUrl = 'NODE_URL';
const repositoryFactory = new bitxor_sdk_1.RepositoryFactoryHttp(nodeUrl);
const restrictionHttp = repositoryFactory.createRestrictionTokenRepository();
const criteria = { tokenId, targetAddress: address };
restrictionHttp.search(criteria).subscribe(
    (tokenAddressRestrictions) => {
        if (tokenAddressRestrictions.data.length > 0) {
            tokenAddressRestrictions.data.forEach((tokenRestriction) => {
                tokenRestriction.restrictions.forEach((value) => {
                    console.log('\n', value.key, value.restrictionValue);
                });
            });
        } else {
            console.log(
                '\n The address does not have token address restrictions assigned.',
            );
        }
    },
    (err) => console.log(err),
);
        // replace with node endpoint
        try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
            "NODE_URL")) {
            final RestrictionTokenRepository restrictionRepository = repositoryFactory
                .createRestrictionTokenRepository();

            // replace with tokenId
            final String tokenIdHex = "634a8ac3fc2b65b3";
            final TokenId tokenId = new TokenId(tokenIdHex);

            // replace with address
            final String rawAddress = "BXRBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I";
            final Address address = Address.createFromRawAddress(rawAddress);

            TokenRestrictionSearchCriteria criteria = new TokenRestrictionSearchCriteria()
                .tokenId(tokenId).targetAddress(address);

            List<TokenAddressRestriction> restrictions = TokenRestrictionPaginationStreamer
                .address(restrictionRepository, criteria).toList().toFuture().get();

            final JsonHelper helper = new JsonHelperJackson2();
            System.out.println(helper.prettyPrint(restrictions));
        }

Method #02: Using the CLI

bitxor-cli restriction tokenaddress --token-id 634a8ac3fc2b65b3 --address BXRBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I