//Example: We want to convert 0.5 BUSD. It has 18 decimals
const busdInWei = Moralis.Units.Token("0.5", "18")
// expected output: 500000000000000000 Wei
代幣的小數(shù)位數(shù)通??梢栽?nbsp;Etherscan、項目網(wǎng)站或 Moralis API 上找到。
將原生資產(chǎn)(ETH/BNB/MATIC 等)轉(zhuǎn)換為 Wei
要將原生資產(chǎn)轉(zhuǎn)換為 Wei,您需要指定原生加密貨幣的數(shù)量。
//Example: We want to convert 0.5 ETH to Wei
const ethInWei = Moralis.Units.ETH("0.5")
// expected output: 500000000000000000 Wei
從 Wei 轉(zhuǎn)換代幣值
所有代幣值均以 Wei 顯示。 如果要以“Eth”樣式顯示令牌值,可以使用:
//Convert token value to ETH style with 6 decimals
const tokenValue = Moralis.Units.FromWei("2000000000000000000", 6)
//Convert token value to ETH style with 18 decimals
//If you do not specify decimals, 18 decimals will be automatically used
const tokenValue = Moralis.Units.FromWei("2000000000000000000")
更多建議: