ss58 1.1.3 copy "ss58: ^1.1.3" to clipboard
ss58: ^1.1.3 copied to clipboard

Provides encoding and decoding methods for parsing substrate SS58 addresses.

example/ss58_example.dart

// ignore_for_file: unused_local_variable
import 'dart:typed_data' show Uint8List;
import 'package:ss58/ss58.dart' show Address, Codec;

void main() {
  // Decoding a Polkadot Address Object
  Address address =
      Address.decode('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY');
  print('Address: $address');

  // Encoding previous Address object
  print('Encoded address: ${address.encode()}');

  // Encoding with a custom prefix
  Address customAddress =
      Address(prefix: 0, pubkey: Uint8List.fromList([1, 2, 3, 4]));
  print('Custom address encoded: ${customAddress.encode()}');

  // get registry info of given `network`
  final kusamaRegistry = Codec.registry.getByNetwork('kusama');

  // get registry info of given `prefix`
  final polkadotRegistry = Codec.registry.getByPrefix(0);

  // decoding substrate address
  final String originalEncodedAddress =
      '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
  final List<int> decodedBytes =
      Codec.fromNetwork('substrate').decode(originalEncodedAddress);

  // Encoding the decodedBytes to produce back encodedAddress.
  final int substrateAddressPrefix = 42;
  final encodedAddress = Codec(substrateAddressPrefix).encode(decodedBytes);
}
1
likes
160
points
1.08k
downloads

Publisher

verified publisherpolkadart.dev

Weekly Downloads

Provides encoding and decoding methods for parsing substrate SS58 addresses.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

base_x, convert, cryptography, equatable

More

Packages that depend on ss58