アカウントにアタッチされたメタデータエントリを取得する

アカウントにアタッチされたメタデータエントリの一覧を取得する

前提条件

方法 #01: 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));
        }

方法 #02: CLI を使用する

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