How to use the @ethersproject/bignumber.BigNumber.isBigNumber function in @ethersproject/bignumber

To help you get started, we’ve selected a few @ethersproject/bignumber 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 OffchainLabs / arbitrum / packages / arb-ts / src / lib / byte_serialize_params.ts View on Github external
const formatPrimative = (value: PrimativeType) => {
  if (isAddress(value)) {
    return value as string
  } else if (typeof value === 'boolean') {
    return toUint(value ? 1 : 0, 1)
  } else if (
    typeof value === 'number' ||
    +value ||
    BigNumber.isBigNumber(value)
  ) {
    return toUint(value, 32)
  } else {
    throw new Error('unsupported type')
  }
}
/**
github ethereum / web3.js / internal / core / src / utility / Hex.js View on Github external
static from(value) {
        if (isBoolean(value)) {
            if (value === true) {
                return new Hex('0x01');
            }

            return new Hex('0x00');
        }

        if (isObject(value) && !BigNumber.isBigNumber(value) && !BN.isBN(value)) {
            return Hex.fromUTF8(JSON.stringify(value));
        }

        if (isString(value)) {
            if (
                value.startsWith('-0x') ||
                value.startsWith('-0X') ||
                value.startsWith('0x') ||
                value.startsWith('0X')
            ) {
                return new Hex(value);
            }

            if (!isFinite(value)) {
                return Hex.fromUTF8(value);
            }
github OffchainLabs / arbitrum / packages / arb-provider-ethers / src / lib / byte_serialize_params.ts View on Github external
const formatPrimative = (value: PrimativeType) => {
  if (isAddress(value)) {
    return value as string
  } else if (typeof value === 'boolean') {
    return toUint(value ? 1 : 0, 1)
  } else if (
    typeof value === 'number' ||
    +value ||
    BigNumber.isBigNumber(value)
  ) {
    return toUint(value, 32)
  } else {
    throw new Error('unsupported type')
  }
}
github ethereum / web3.js / internal / ethereum / lib / types / utility / Units.js View on Github external
static toWei(number, unit) {
        unit = Units.getUnitValue(unit);

        if (BigNumber.isBigNumber(number) || BN.isBN(number)) {
            return BigNumber.from(ethjsUnit.toWei(number, unit).toString(10));
        }

        if (isString(number)) {
            return ethjsUnit.toWei(number, unit).toString(10);
        }

        throw new Error('Please pass numbers as strings or BN objects to avoid precision errors.');
    }
}
github ethereum / web3.js / internal / ethereum / lib / types / utility / Units.js View on Github external
static fromWei(number, unit) {
        unit = Units.getUnitValue(unit);

        if (BigNumber.isBigNumber(number) || BN.isBN(number)) {
            return BigNumber.from(ethjsUnit.fromWei(number, unit).toString(10));
        }

        if (isString(number)) {
            return ethjsUnit.fromWei(number, unit).toString(10);
        }

        throw new Error('Please pass numbers as strings or BN objects to avoid precision errors.');
    }
github ethereum / web3.js / internal / core / src / utility / Hex.js View on Github external
if (isString(value)) {
            if (
                value.startsWith('-0x') ||
                value.startsWith('-0X') ||
                value.startsWith('0x') ||
                value.startsWith('0X')
            ) {
                return new Hex(value);
            }

            if (!isFinite(value)) {
                return Hex.fromUTF8(value);
            }
        }

        if (BigNumber.isBigNumber(value)) {
            let hex = value.toString(16);

            if (value.toHexString) {
                hex = value.toHexString();
            }

            if (hex.startsWith('-')) {
                return new Hex('-0x' + hex.slice(1));
            }

            return new Hex('0x' + value.toString(16));
        }

        if (BN.isBN(value)) {
            const hex = value.toString(16);