UNPKG

avail-js-sdk

Version:

Avail library of functions to interact with blockchain and manipulate transactions

85 lines (84 loc) 3.32 kB
import { ApiPromise } from "@polkadot/api"; import { Keyring } from "@polkadot/keyring"; import { KeyringPair } from "@polkadot/keyring/types"; import { BN } from "@polkadot/util"; export * from "./types"; /** * * This function checks if a given address is valid. * * @param {string} address The address to validate. * * @returns {boolean} A boolean value indicating whether the address is valid or not. */ export declare const isValidAddress: (address: string) => boolean; /** * Formats a number to balance. * * @param {number | string} value The number value to format. * @param {number} [decimals] The number of decimal places to include in the formatted balance. Defaults to 18. * * @returns {BN} The converted BN value. */ export declare const formatNumberToBalance: (value: number | string, decimals?: number) => BN; /** * Generates a new keyring. * * @returns {Keyring} The newly generated Keyring instance. */ export declare const generateKeyring: () => Keyring; /** * Retrieves a keyring pair from a given seed. * * @param {string} seed The seed value used to generate the keypair. * @returns {KeyringPair} The KeyringPair generated from the seed. */ export declare const getKeyringFromSeed: (seed: string) => KeyringPair; /** * Splits a string into an array of substrings of a specified chunk size. * * @param {string} inputString The input string to split. * @param {number} chunkSize The size of each chunk. Default is 2. * @returns {string[]} An array of substrings. */ export declare const splitStringIntoArray: (inputString: string, chunkSize?: number) => string[]; /** * Decodes a Uint8Array into a decimal value. * * @param {Uint8Array} value The Uint8Array to decode. * @returns {string} The decoded hex-encoded App ID as a string. */ export declare const decodeU8IntAppId: (value: Uint8Array) => string; /** * Decodes a hex-encoded App ID string into a decimal value. * * @param {string} value The hex-encoded App ID string to decode. * @returns {string} The decoded decimal value as a string. * @throws {Error} If the input value has an invalid length. */ export declare const decodeHexAppId: (value: `0x${string}`) => string; /** * Extracts the data from a da submission * * @param {ApiPromise} api the api to interact with the chain. * @param {string} blockHash the hash of the block to query at. * @param {string} extrinsicHash the hash of the extrinsic to query at. * @return {Promise<string>} the bytes representing the data * @throws {Error} If the api is not connected, the block is empty or non existant, the extrinsic hash is non existant */ export declare const extractData: (api: ApiPromise, blockHash: string, extrinsicHash: string) => Promise<string>; /** * Converts a hexadecimal string to an ASCII string. * * @param {string} hex - The hexadecimal string to convert. * @return {string} The converted ASCII string. */ export declare function fromHexToAscii(hex: string): string; /** * Decodes a runtime error from the Substrate chain. * * @param {ApiPromise} api - The API instance to interact with the chain. * @param {any} error - The error object to decode. * @return {string} The decoded error message in the format "section.method: description". */ export declare function decodeError(api: ApiPromise, error: any): string;