Friendly token amount
Line 1: | Line 1: | ||
− | '''$ | + | '''$formatted balance''' is a function that allows you to get the amount of a token with the decimal placed accurately. |
+ | |||
+ | This function essentially takes an amount of a token and adjusts it to have the decimal in the correct place based on the token's decimals value. | ||
== Parameters == | == Parameters == | ||
− | '''Chain:''' The blockchain | + | '''Chain:''' The specified blockchain chain where the token exists. The available options are "Avalanche" or "BinanceSmartChain". |
− | '''Token ID:''' The | + | '''Token ID:''' The token for which the formatted balance must be calculated. |
− | '''Amount:''' The | + | '''Amount:''' The total amount of the token represented as a string. |
== Return Value == | == Return Value == | ||
− | This function returns a string | + | This function returns a string, which is the calculated amount of the token adjusted to the correct decimal places. |
== Example == | == Example == | ||
− | |||
<pre> | <pre> | ||
− | + | log("Formatted Binance Coin Balance: {$formatted balance("BinanceSmartChain", "BNB", "100000000000000000")}") | |
− | + | ||
− | log(" | + | |
</pre> | </pre> | ||
− | + | The output of this function will be the amount of the token, placed accurately on the decimal point. | |
− | + | Example Output: | |
<blockquote> | <blockquote> | ||
− | + | <p>Formatted Binance Coin Balance: 10 BNB</p> | |
</blockquote> | </blockquote> | ||
+ | |||
+ | It's important to note that the "Amount" parameter must be provided as a string, even though it represents a numerical value. This is because the value may be larger than the maximum size of a number. |
Revision as of 19:07, 4 July 2023
$formatted balance is a function that allows you to get the amount of a token with the decimal placed accurately.
This function essentially takes an amount of a token and adjusts it to have the decimal in the correct place based on the token's decimals value.
Parameters
Chain: The specified blockchain chain where the token exists. The available options are "Avalanche" or "BinanceSmartChain".
Token ID: The token for which the formatted balance must be calculated.
Amount: The total amount of the token represented as a string.
Return Value
This function returns a string, which is the calculated amount of the token adjusted to the correct decimal places.
Example
log("Formatted Binance Coin Balance: {$formatted balance("BinanceSmartChain", "BNB", "100000000000000000")}")
The output of this function will be the amount of the token, placed accurately on the decimal point.
Example Output:
Formatted Binance Coin Balance: 10 BNB
It's important to note that the "Amount" parameter must be provided as a string, even though it represents a numerical value. This is because the value may be larger than the maximum size of a number.