Getting metadata entries attached to a namespace

Get the list of metadata entries attached to an namespace.

Prerequisites

Method #01: Using the SDK

// replace with namespace name
const namespaceId = new NamespaceId('symbol');
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const metadataHttp = repositoryFactory.createMetadataRepository();

const searchCriteria = {targetId: namespaceId, metadataType: MetadataType.Namespace};
metadataHttp.search(searchCriteria)
    .subscribe((metadata) => {
        if (metadata.totalEntries > 0) {
            console.log('Page', metadata.pageNumber, 'of', metadata.totalPages);
            metadata.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());
                    console.log('\n TargetId:\t', metadataEntry.targetId);
                });
        } else {
            console.log('\n The namespace does not have metadata entries assigned.');
        }
    }, (err) => console.log(err));
// replace with namespace name
const namespaceId = new symbol_sdk_1.NamespaceId('symbol');
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const metadataHttp = repositoryFactory.createMetadataRepository();
const searchCriteria = { targetId: namespaceId, metadataType: symbol_sdk_1.MetadataType.Namespace };
metadataHttp.search(searchCriteria)
    .subscribe((metadata) => {
    if (metadata.totalEntries > 0) {
        console.log('Page', metadata.pageNumber, 'of', metadata.totalPages);
        metadata.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());
            console.log('\n TargetId:\t', metadataEntry.targetId);
        });
    }
    else {
        console.log('\n The namespace does not have metadata entries assigned.');
    }
}, (err) => console.log(err));
        // replace with node endpoint
        try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
            "http://api-01.us-east-1.096x.symboldev.network:3000")) {
            final MetadataRepository metadataRepository = repositoryFactory
                .createMetadataRepository();

            // replace with namespace name
            final String namespaceName = "symbol";
            final NamespaceId namespaceId = NamespaceId.createFromName(namespaceName);

            MetadataPaginationStreamer streamer = new MetadataPaginationStreamer(
                metadataRepository);
            MetadataSearchCriteria criteria = new MetadataSearchCriteria().targetId(namespaceId);
            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 namespace --namespace-name foo