Friendly token amount
$get token amount is a function that returns an amount of a specific token with the decimal in the correct place.
It is important because cryptocurrencies often have different decimal places - for example, Ether has 18 decimal places.
Parameters
Chain: The blockchain network (such as Avalanche or BinanceSmartChain) where the token resides.
Token ID: The token for which you want to get the amount with the right decimal places. You can select from the dropdown list or manually enter the contract address if your desired token isn't listed.
Amount: The raw amount of the token you want to convert to the correct decimal places.
Return Value
This function returns a string that represents the correctly formatted amount of the specified token.
Example
log("Correctly formatted token amount: {$get token amount("Avalanche", "AVAX", "1000000000000000000")}")
The above script logs the correctly formatted amount of AVAX for the raw amount of "1000000000000000000" on the Avalanche blockchain. For an AVAX amount of "1000000000000000000" raw units, the correct amount would be "1" AVAX because AVAX has 18 decimal places, similar to Ether.
- Please note:**
Be sure to correctly input the raw amount, as it directly affects the result. Misinterpretation of the raw amount can lead to significant discrepancies in the resulting value.