readBlobAttributes method
Read the on-chain attributes (metadata key-value pairs) for a blob.
Returns null if the blob has no metadata attached.
Returns a Map<String, String> of key-value pairs otherwise.
Uses Sui dynamic field lookup for the metadata key on the blob object.
Mirrors the TS SDK's readBlobAttributes().
Implementation
Future<Map<String, String>?> readBlobAttributes({
required String blobObjectId,
}) async {
try {
// The metadata is stored as a dynamic field on the blob object
// with key type `vector<u8>` and key value b"metadata".
//
// The Dart `sui` package's `getDynamicFieldObject` only accepts a
// String for the name value, but for `vector<u8>` the Sui JSON-RPC
// expects a JSON array of byte integers. Use a raw RPC call instead.
final nameValue = 'metadata'.codeUnits; // UTF-8 byte array
final result = await suiClient.client.request(
'suix_getDynamicFieldObject',
[
blobObjectId,
{'type': 'vector<u8>', 'value': nameValue},
],
);
final response = SuiObjectResponse.fromJson(result);
final content = response.data?.content;
if (content == null) return null;
// Parse the metadata VecMap from the dynamic field content.
return _parseMetadataContent(content);
} catch (e) {
// Dynamic field not found → no metadata attached.
if (e.toString().contains('DynamicFieldNotFound') ||
e.toString().contains('not found') ||
e.toString().contains('404')) {
return null;
}
rethrow;
}
}