Socket
Socket
Sign inDemoInstall

@polkadot/types

Package Overview
Dependencies
Maintainers
2
Versions
3031
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polkadot/types

Implementation of the Parity codec


Version published
Maintainers
2
Created

What is @polkadot/types?

@polkadot/types is a library for handling types and encoding/decoding of data for the Polkadot and Substrate ecosystem. It provides a comprehensive set of tools for working with the various types used in the Polkadot network, including creating, parsing, and validating data structures.

What are @polkadot/types's main functionalities?

Creating and Using Custom Types

This feature allows you to create and use custom types. In this example, a custom type 'u32' is created and initialized with the value 12345.

const { TypeRegistry } = require('@polkadot/types');
const registry = new TypeRegistry();
const MyCustomType = registry.createType('u32', 12345);
console.log(MyCustomType.toString()); // '12345'

Encoding and Decoding Data

This feature allows you to encode and decode data. In this example, a 'u32' type is encoded to a Uint8Array and then decoded back to its original value.

const { TypeRegistry } = require('@polkadot/types');
const registry = new TypeRegistry();
const encoded = registry.createType('u32', 12345).toU8a();
const decoded = registry.createType('u32', encoded);
console.log(decoded.toString()); // '12345'

Working with Complex Types

This feature allows you to work with complex types such as vectors and tuples. In this example, a vector of tuples containing 'u32' and 'bool' types is created and logged.

const { TypeRegistry } = require('@polkadot/types');
const registry = new TypeRegistry();
const ComplexType = registry.createType('Vec<(u32, bool)>', [[1, true], [2, false]]);
console.log(ComplexType.toString()); // '[[1,true],[2,false]]'

Other packages similar to @polkadot/types

FAQs

Package last updated on 19 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc