Skip to main content

Units

For units conversion, Kaia-sdk supports utils for converting kaia, Gkei and kei. See supported units .

Import the formatKlay, parseKlay, formatKlayUnits, from @kaiachain/ethers-ext packages

To convert peb to other units, use formatKlayUnits. For example, using formatKlayUnits converting peb to ston

Using formatKlay converts peb to klay

Using parseKlayUnits to convert value from one unit to peb. The first param is the value, the second param is the unit to be converted

Using parseKlay to convert klay to peb

unitUtils.js

const {
formatKlay,
parseKlay,
formatKlayUnits,
} = require('@kaiachain/ethers-ext/v5')
async function main() {
console.log(
'example basefee in ston =',
formatKlayUnits('0x5d21dba00', 'ston')
)
console.log('transfer amount in klay =', formatKlay('1230000000000000000'))
console.log(
'example gas price in peb =',
parseKlayUnits('50', 'ston').toString()
)
console.log('transfer amount in peb =', parseKlay('9.87').toString())
}
main()

output

❯ node unitUtils.js
example basefee in ston = 25.0
transfer amount in klay = 1.23
example gas price in peb = 50000000000
transfer amount in peb = 9870000000000000000

Make this page better