Getting metadata entries attached to an account

Get the list of metadata entries attached to an account.

Getting into some code

Get all metadata entries

const rawAddress = process.env.ADDRESS as string;
const address = Address.createFromRawAddress(rawAddress);

const metadataHttp = new MetadataHttp('http://localhost:3000');
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));
nem2-cli metadata account --address SD5DT3-CH4BLA-BL5HIM-EKP2TA-PUKF4N-Y3L5HR-IR54

Filter metadata entries by key

const rawAddress = process.env.ADDRESS as string;
const address = Address.createFromRawAddress(rawAddress);
const keyHex = process.env.KEY as string;

const metadataHttp = new MetadataHttp('http://localhost:3000');
metadataHttp.getAccountMetadataByKey(address, keyHex)
    .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 for this key.');
        }
    }, (err) => console.log(err));

Filter metadata entries by key and sender

const rawAddress = process.env.ADDRESS as string;
const address = Address.createFromRawAddress(rawAddress);
const senderPublicKey = process.env.SENDER_PUBLIC_KEY as string;
const keyHex = process.env.KEY as string;

const metadataHttp = new MetadataHttp('http://localhost:3000');
metadataHttp.getAccountMetadataByKeyAndSender(address, keyHex, senderPublicKey)
    .subscribe((metadata) => {
            const metadataEntry = metadata.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);
    }, (err) => console.log(err));