Files
common/docs/bn.md
T
2017-11-21 00:11:09 +01:00

994 B

bn

Utility methods to convert to and from BN objects

  • (bnFromHex)[#bnFromHex] Creates a BN.js bignumber object from a hex string.
  • (bnToHex)[#bnToHex] Creates a hex value from a BN.js bignumber object.

bnFromHex

Creates a BN.js bignumber object from a hex string.

bnFromHex (value?: string): BN

null inputs returns a BN(0) result. Hex input values return the actual value converted to a BN. Anything that is not a hex string (including the 0x prefix) throws an error.

import { bnFromHex } from '@polkadot/util';

console.log('BN object', bnFromHex('0x123480001f'));

bnToHex

Creates a hex value from a BN.js bignumber object.

bnToHex (value?: BN): string

null inputs returns a 0x result, BN values return the actual value as a 0x prefixed hex value. Anything that is not a BN object throws an error.

import BN from 'bn.js';
import { bnToHex } from '@polkadot/util';

console.log('Hex value', bnToHex(new BN(123456));