Getting metadata entries attached to an account

Get the list of metadata entries attached to an account.

Prerequisites

Method #01: Using the SDK

// Replace with address
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = Address.createFromRawAddress(rawAddress);
// Replace with node endpoint
const nodeUrl = 'NODE_URL';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const metadataHttp = repositoryFactory.createMetadataRepository();

const searchCriteria = {
  targetAddress: address,
  metadataType: MetadataType.Account,
};
metadataHttp.search(searchCriteria).subscribe(
  (metadataEntries: Page<Metadata>) => {
    if (metadataEntries.pageSize > 0) {
      console.log('Page', metadataEntries.pageNumber);
      metadataEntries.data.map((entry: Metadata) => {
        const metadataEntry = entry.metadataEntry;
        console.log('\n \n Key:\t', metadataEntry.scopedMetadataKey);
        console.log('\n ---');
        console.log('\n Value:\t', metadataEntry.value);
        console.log(
          '\n Sender Address:\t',
          metadataEntry.sourceAddress.pretty(),
        );
        console.log(
          '\n Target address:\t',
          metadataEntry.targetAddress.pretty(),
        );
        console.log(
          '\n Scoped metadata key:\t',
          metadataEntry.scopedMetadataKey.toHex(),
        );
      });
    } else {
      console.log('\n The address does not have metadata entries assigned.');
    }
  },
  (err) => console.log(err),
);
// Replace with address
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = symbol_sdk_1.Address.createFromRawAddress(rawAddress);
// Replace with node endpoint
const nodeUrl = 'NODE_URL';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const metadataHttp = repositoryFactory.createMetadataRepository();
const searchCriteria = {
    targetAddress: address,
    metadataType: symbol_sdk_1.MetadataType.Account,
};
metadataHttp.search(searchCriteria).subscribe((metadataEntries) => {
    if (metadataEntries.pageSize > 0) {
        console.log('Page', metadataEntries.pageNumber);
        metadataEntries.data.map((entry) => {
            const metadataEntry = entry.metadataEntry;
            console.log('\n \n Key:\t', metadataEntry.scopedMetadataKey);
            console.log('\n ---');
            console.log('\n Value:\t', metadataEntry.value);
            console.log('\n Sender Address:\t', metadataEntry.sourceAddress.pretty());
            console.log('\n Target address:\t', metadataEntry.targetAddress.pretty());
            console.log('\n Scoped metadata key:\t', metadataEntry.scopedMetadataKey.toHex());
        });
    }
    else {
        console.log('\n The address does not have metadata entries assigned.');
    }
}, (err) => console.log(err));
        // replace with node endpoint
        try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
            "NODE_URL")) {
            final MetadataRepository metadataRepository = repositoryFactory
                .createMetadataRepository();

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

            MetadataPaginationStreamer streamer = new MetadataPaginationStreamer(
                metadataRepository);
            MetadataSearchCriteria criteria = new MetadataSearchCriteria().targetAddress(address);
            final List<Metadata> metadata = streamer
                .search(criteria).toList().toFuture()
                .get();

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

Method #02: Using the CLI

symbol-cli metadata account --address TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I