docs ⦿ dedot 🧑‍💻
TypinkXTelegramGithub
dedot 🧑‍💻
dedot 🧑‍💻
  • Welcome to Dedot
  • Why Dedot?
  • Getting started
    • Installation
    • Connect to network
    • @polkadot/api -> dedot
    • Packages structure
  • Clients & Providers
    • Providers
    • Clients
  • Client API
    • ChainApi
    • Constants
    • Runtime APIs
    • Storage Queries
    • Transactions
    • Events
    • Errors
  • ink! Smart Contracts
    • Introduction
    • Generate Types & APIs
    • Deploy contracts
    • Queries
    • Transactions
    • Events
    • Handle errors
  • CLI
  • Keyring & Signer
  • Runtime upgrades
  • Type system
  • Utilities
    • HexString
    • Uint8Array (U8a)
    • String
    • Hash functions
    • Address
    • BigInt & number
    • Balances
    • Merkleized Metadata
  • Help & FAQ
    • Tutorials
      • Develop ink! dApp using Typink
    • Built with Dedot
    • Forum Posts
    • Telegram
    • Github
    • API Reference
Powered by GitBook
On this page
  • hexToU8a
  • hexToString
  • isZeroHex
  • hexAddPrefix & hexStripPrefix
  • toHex

Was this helpful?

Edit on GitHub
  1. Utilities

HexString

hexToU8a

Converts a hex string to a Uint8Array

import { hexToU8a } from 'dedot/utils';

hexToU8a('0x1234') // new Uint8Array([0x12, 0x34])

hexToString

Converts a hex to a string

import { hexToString } from 'dedot/utils';

hexToString('0x616263') // 'abc'

isZeroHex

Check if a hex is zero

import { isZeroHex } from 'dedot/utils';

isZeroHex('0x00000000') // true
isZeroHex('0x00000001') // false

hexAddPrefix & hexStripPrefix

Add/remove the '0x' prefix to/from a hex string

import { hexAddPrefix, hexStripPrefix } from 'dedot/utils';

hexAddPrefix('00000000') // '0x00000000'
hexAddPrefix('0x00000001') // '0x00000001'

hexStripPrefix('00000000') // '00000000'
hexStripPrefix('0x00000001') // '00000001'

toHex

Converts the input to a hex string, input can be in different types: string | number | Uint8Array | HexString

import { toHex } from 'dedot/utils';

toHex(new Uint8Array([0x12, 0x34])) // '0x1234'
toHex(4660) // '0x1234'
toHex('0x1234') // '0x1234'
toHex('abc') // '0x1234'
PreviousUtilitiesNextUint8Array (U8a)

Last updated 8 months ago

Was this helpful?