Get the list of metadata entries attached to an token.
Complete assigning metadata entries to a token guide.
// replace with token id
const tokenIdHex = '0DC67FBE1CAD29E3';
const tokenId = new TokenId(tokenIdHex);
// replace with node endpoint
const nodeUrl = 'NODE_URL';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const metadataHttp = repositoryFactory.createMetadataRepository();
const searchCriteria = {
targetId: tokenId,
metadataType: MetadataType.Token,
};
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(),
);
console.log('\n TargetId:\t', metadataEntry.targetId);
});
} else {
console.log('\n The token does not have metadata entries assigned.');
}
},
(err) => console.log(err),
);
// replace with token id
const tokenIdHex = '0DC67FBE1CAD29E3';
const tokenId = new bitxor_sdk_1.TokenId(tokenIdHex);
// replace with node endpoint
const nodeUrl = 'NODE_URL';
const repositoryFactory = new bitxor_sdk_1.RepositoryFactoryHttp(nodeUrl);
const metadataHttp = repositoryFactory.createMetadataRepository();
const searchCriteria = {
targetId: tokenId,
metadataType: bitxor_sdk_1.MetadataType.Token,
};
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(),
);
console.log('\n TargetId:\t', metadataEntry.targetId);
});
} else {
console.log('\n The token 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 token id
final String tokenIdHex = "0DC67FBE1CAD29E3";
final TokenId tokenId = new TokenId(tokenIdHex);
MetadataPaginationStreamer streamer = new MetadataPaginationStreamer(
metadataRepository);
MetadataSearchCriteria criteria = new MetadataSearchCriteria().targetId(tokenId);
final List<Metadata> metadata = streamer
.search(criteria).toList().toFuture().get();
final JsonHelper helper = new JsonHelperJackson2();
System.out.println(helper.prettyPrint(metadata));
}
bitxor-cli metadata token --token-id 71415AC19C818709