Gathering detailed insights and metrics for @polkadot-api/metadata-builders
Gathering detailed insights and metrics for @polkadot-api/metadata-builders
Gathering detailed insights and metrics for @polkadot-api/metadata-builders
Gathering detailed insights and metrics for @polkadot-api/metadata-builders
Polkadot-API is a meticulously crafted suite of libraries, each designed to be composable, modular, and aligned with a "light-client first" philosophy.
npm install @polkadot-api/metadata-builders
Typescript
Module System
Node Version
NPM Version
99.6
Supply Chain
98.3
Quality
90.1
Maintenance
100
Vulnerability
100
License
polkadot-api@1.14.0
Updated on Jun 16, 2025
polkadot-api@1.13.1
Updated on Jun 04, 2025
polkadot-api@1.13.0
Updated on Jun 02, 2025
polkadot-api@1.12.2
Updated on May 29, 2025
polkadot-api@1.12.1
Updated on May 27, 2025
polkadot-api@1.12.0
Updated on May 22, 2025
TypeScript (98.23%)
JavaScript (1.63%)
Dockerfile (0.1%)
Shell (0.04%)
Total Downloads
4,279,596
Last Day
3,246
Last Week
113,771
Last Month
457,680
Last Year
3,905,613
MIT License
132 Stars
1,060 Commits
37 Forks
12 Watchers
7 Branches
14 Contributors
Updated on Jul 03, 2025
Minified
Minified + Gzipped
Latest Version
0.12.2
Package Id
@polkadot-api/metadata-builders@0.12.2
Unpacked Size
241.30 kB
Size
53.33 kB
File Count
20
NPM Version
10.8.2
Node Version
20.19.1
Published on
May 30, 2025
Cumulative downloads
Total Downloads
Last Day
-31.6%
3,246
Compared to previous day
Last Week
-3.6%
113,771
Compared to previous week
Last Month
8.2%
457,680
Compared to previous month
Last Year
944.3%
3,905,613
Compared to previous year
2
1
This package has multiple functions that read a metadata object, denormalizes it, and builds other structures needed for different processes
## getLookupFn
1interface MetadataLookup { 2 (id: number): LookupEntry 3 metadata: V14 | V15 4} 5 6function getLookupFn(metadata: Metadata): MetadataLookup
Given the a metadata, returns a function that will give the LookupEntry
for an id along. The function also has access to the original metadata, as it's usually needed to work with the actual lookup.
The LookupEntry
is a denormalized data structure for one entry in the metadata. It also "shortcuts" type references when those are pointers (composites or tuples of length 1). Essentially, it's a union of each of the different types that can be found in the lookup, mostly equivalent to something like:
1type TerminalVar = 2 | PrimitiveVar // u8, str, char, i128, etc. 3 | CompactVar 4 | BitSequenceVar 5 | AccountId32 6 7type ComposedVar = 8 | TupleVar 9 | StructVar 10 | SequenceVar 11 | ArrayVar 12 | OptionVar 13 | ResultVar 14 | EnumVar 15 16type LookupEntry = TerminalVar | ComposedVar
Where, for instance, a StructVar is of the shape
1type StructVar = { 2 type: "struct" 3 value: Record<string, LookupEntry> 4}
It's useful to get types referenced by storage calls, etc.
1function getDynamicBuilder(metadataLookup: MetadataLookup): { 2 buildDefinition: (id: number) => Codec 3 buildConstant: (pallet: string, name: string) => Codec 4 buildEvent: (pallet: string, name: string) => VariantEntry 5 buildError: (pallet: string, name: string) => VariantEntry 6 buildCall: (pallet: string, name: string) => VariantEntry 7 buildStorage: (pallet: string, entry: string) => StorageEntry 8 buildRuntimeCall: (api: string, method: string) => RuntimeEntry 9}
Generates all the codecs needed to SCALE encode or decode the data for any interaction with the chain.
buildDefinition
returns the codec for the type identified by the parameter id
buildConstant
returns the codec for the requested constant (equivalent as calling buildDefinition
with the type id of that constant)
buildEvent
, buildError
and buildCall
return an object with the codec, and the indices of the pallet and entry within the metadata:
1interface VariantEntry { 2 location: [number, number] // [palletIdx, entryIdx], 3 codec: Codec 4}
buildStorage
creates all the encoders/decoders needed to encode a storage call and decode its result:
1interface StorageEntry { 2 // Encodes the arguments of the storage call. 3 enc: (...args: any[]) => string 4 // Decodes the result from the storage call. 5 dec: (value: string) => any 6 // Decodes the arguments of the storage call 7 keyDecoder: (value: string) => any[] 8 // Expected number of arguments 9 len: number 10 // Decoded fallback value as defined in the metadata entry 11 fallback: unknown 12}
Similarly, buildRuntimeCall
returns the codecs for both encoding the arguments of the runtime call, and the codec for decoding the result
1interface RuntimeEntry { 2 args: Codec<any[]> 3 value: Codec<any> 4}
1function getChecksumBuilder(metadataLookup: MetadataLookup): { 2 buildDefinition: (id: number) => string | null 3 buildRuntimeCall: (api: string, method: string) => string | null 4 buildStorage: (pallet: string, entry: string) => string | null 5 buildCall: (pallet: string, name: string) => string | null 6 buildEvent: (pallet: string, name: string) => string | null 7 buildError: (pallet: string, name: string) => string | null 8 buildConstant: (pallet: string, constantName: string) => string | null 9}
Generates the checksums for the different components defined in the metadata.
buildDefinition
builds the checksum of one of the types in the lookup. The rest of the methods build the checksum for each of the interfaces of the chain.
No vulnerabilities found.
No security vulnerabilities found.