Skip to content

@ecp.eth/sdk


@ecp.eth/sdk / comments / convertContractToRecordFormat

Function: convertContractToRecordFormat()

function convertContractToRecordFormat(metadataEntries, keyTypeMap?): MetadataRecord;

Defined in: packages/sdk/src/comments/metadata.ts:564

Converts from contract MetadataEntry array format to JS/SDK Record format Note: This requires knowledge of the original key string and type, which are lost in the contract format. This function attempts to reverse-engineer them from common patterns used in the codebase.

Parameters

metadataEntries

MetadataEntry[]

Array of MetadataEntry from contracts

keyTypeMap?

MetadataKeyTypeMap

Optional mapping of known keys to their original string and type. If not provided, the key in the record will be the hex hash of the key and the type will be "bytes".

Returns

MetadataRecord

The metadata in Record format

Examples

// if key to type map provided is provided
const result = convertContractToRecordFormat(metadataEntries, createKeyTypeMap([{ key: "status", type: "string" }]));
console.log(result);
// {
//   "strin status": {
//     key: "status",
//     type: "string",
//     value: "0x0000000000000000000000000000000000000000000000000000000000000000",
//   },
}
// if key to type map not provided returns object like this
const result = convertContractToRecordFormat(metadataEntries);
console.log(result);
// {
//   "0x0000000000000000000000000000000000000000000000000000000000000000": {
//     key: "0x0000000000000000000000000000000000000000000000000000000000000000",
//     type: "bytes",
//     value: "0x0000000000000000000000000000000000000000000000000000000000000000",
//   },
}