How to use the bn.js.BN function in bn

To help you get started, we’ve selected a few bn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github unstoppabledomains / browseth / src / explorer.ts View on Github external
function checkIfString(val: string | number) {
  if (typeof val === 'string') {
    if (/[g-z]/i.test(val)) {
      // if 'latest' 'earliest' 'pending'
      return val;
    }
    return /^0x/i.test(val) ? val : '0x' + new BN(val).toString(16);
  }
  return '0x' + val.toString(16);
}
github JoinColony / colonyNetwork / packages / reputation-miner / ReputationMiner.js View on Github external
async printCurrentState() {
    for (let i = 0; i < Object.keys(this.reputations).length; i += 1) {
      const key = Object.keys(this.reputations)[i];
      const decimalValue = new BN(this.reputations[key].slice(2, 66), 16);
      const keyElements = ReputationMiner.breakKeyInToElements(key);
      const [colonyAddress, , userAddress] = keyElements;
      const skillId = parseInt(keyElements[1], 16);

      console.log("colonyAddress", colonyAddress);
      console.log("userAddress", userAddress);
      console.log("skillId", skillId);
      console.log("value", decimalValue.toString());
      console.log("---------");
    }
  }
github neo-one-suite / neo-one / packages / neo-one-client-common / src / common.ts View on Github external
const fixedFromDecimal = (value: number | string | BigNumber | BN, decimals: number) => {
  if (value instanceof BN) {
    return value;
  }

  const d = new BN(10 ** decimals);
  if (typeof value === 'number') {
    return new BN(value).mul(d);
  }

  const valueBigNumber = typeof value === 'string' ? new BigNumber(value) : value;
  const dBigNumber = new BigNumber(d.toString(10));

  return new BN(valueBigNumber.times(dBigNumber).toString(), 10);
};
github ethers-io / ethers.js / packages / bignumber / lib.esm / bignumber.js View on Github external
function toBN(value) {
    const hex = BigNumber.from(value).toHexString();
    if (hex[0] === "-") {
        return (new BN("-" + hex.substring(3), 16));
    }
    return new BN(hex.substring(2), 16);
}
function throwFault(fault, operation, value) {
github ethers-io / ethers.js / packages / bignumber / lib.esm / bignumber.js View on Github external
function toBN(value) {
    const hex = BigNumber.from(value).toHexString();
    if (hex[0] === "-") {
        return (new BN("-" + hex.substring(3), 16));
    }
    return new BN(hex.substring(2), 16);
}
function throwFault(fault, operation, value) {

bn

JS Bigint import

BSD-3-Clause
Latest version published 5 years ago

Package Health Score

50 / 100
Full package analysis

Popular bn functions