본문으로 건너뛰기
This page uses machine translation from English, which may contain errors or unclear language. For the most accurate information, please see the original English version. Some content may be in the original English due to frequent updates. Help us improve this page's translation by joining our effort on Crowdin. (Crowdin translation page, Contributing guide)

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

페이지를 개선해 주세요