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 = 'TBULEA-UG2CZQ-ISUR44-2HWA6U-AKGWIX-HDABJV-IPS4';
const address = Address.createFromRawAddress(rawAddress);
// Replace with node endpoint
const nodeUrl = 'http://api-01.ap-northeast-1.testnet-0951-v1.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const metadataHttp = repositoryFactory.createMetadataRepository();

metadataHttp.getAccountMetadata(address)
    .subscribe((metadata) => {
        if (metadata.length > 0) {
            metadata
                .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 Public Key:\t', metadataEntry.senderPublicKey);
                    console.log('\n Scoped Metadata Key:\t', metadataEntry.targetPublicKey);
                });
        } else {
            console.log('\n The address does not have metadata entries assigned.');
        }
    }, (err) => console.log(err));
// Replace with address
const rawAddress = 'TBULEA-UG2CZQ-ISUR44-2HWA6U-AKGWIX-HDABJV-IPS4';
const address = symbol_sdk_1.Address.createFromRawAddress(rawAddress);
// Replace with node endpoint
const nodeUrl = 'http://api-01.ap-northeast-1.testnet-0951-v1.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const metadataHttp = repositoryFactory.createMetadataRepository();
metadataHttp.getAccountMetadata(address)
    .subscribe((metadata) => {
    if (metadata.length > 0) {
        metadata
            .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 Public Key:\t', metadataEntry.senderPublicKey);
            console.log('\n Scoped Metadata Key:\t', metadataEntry.targetPublicKey);
        });
    }
    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(
                "http://api-01.ap-northeast-1.testnet-0951-v1.symboldev.network:3000")) {
            final MetadataRepository metadataRepository = repositoryFactory.createMetadataRepository();

            // replace with address
            final String rawAddress = "TBULEA-UG2CZQ-ISUR44-2HWA6U-AKGWIX-HDABJV-IPS4";
            final Address address = Address.createFromRawAddress(rawAddress);

            final List<Metadata> metadata = metadataRepository.getAccountMetadata(address, Optional.empty())
                    .toFuture().get();
            final JsonHelper helper = new JsonHelperJackson2();
            System.out.println(helper.prettyPrint(metadata));
        }

Method #02: Using the CLI

symbol-cli metadata account --address TBULEA-UG2CZQ-ISUR44-2HWA6U-AKGWIX-HDABJV-IPS4