klaytn/caver-js

Error when convert BigNumber to Peb

Closed this issue · 0 comments

SFzxc commented

Describe the bug
I got a parsing error when trying to convert BigNumber to Peb

/wallet/node_modules/caver-js/packages/caver-utils/src/index.js:346
        throw new Error('Please pass numbers as strings or BigNumber objects to avoid precision errors.')
        ^

Error: Please pass numbers as strings or BigNumber objects to avoid precision errors.
    at tryNumberToString (/wallet/node_modules/caver-js/packages/caver-utils/src/index.js:346:15)
    at toPeb (wallet/node_modules/caver-js/packages/caver-utils/src/index.js:308:18)
    at Object.convertToPeb (/wallet/node_modules/caver-js/packages/caver-utils/src/index.js:338:23)
    at Object.<anonymous> (/wallet/index.js:27:25)

How to reproduce

const Caver = require('caver-js')
const caver = new Caver('https://api.baobab.klaytn.net:8651')
const BigNumber = require('bignumber.js')

console.log(caver.utils.convertToPeb(new BigNumber(2.5), 'KLAY'));

Expected behavior
Expected: 2500000000000000000

Attachments
If applicable, add data, logs or screenshots to help explain your problem.

Environment (please complete the following information)

  • caver-js last version
  • MacOS

Additional context
Add any other context about the problem here.