Friendly token amount

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
'''$get proper token amount''' is a function that returns the amount of a specified token with the decimal in the correct place. This command is very useful for enterprise users managing transactions with various tokens, ensuring the correct token quantities are used.  
+
'''$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 network chain associated with the token. Available options include Avalanche and Binance Smart Chain.
+
'''Chain:''' The specified blockchain chain where the token exists. The available options are "Avalanche" or "BinanceSmartChain".
  
'''Token ID:''' The identifier of the token for which the correct amount is to be obtained. If your desired token is not available in the dropdown, you can input its contract address.
+
'''Token ID:''' The token for which the formatted balance must be calculated.
  
'''Amount:''' The raw quantity of the specified token that needs to be adjusted for decimals.
+
'''Amount:''' The total amount of the token represented as a string.
  
 
== Return Value ==
 
== Return Value ==
  
This function returns a string that represents the correct amount of the specified token, considering the decimal placement.
+
This function returns a string, which is the calculated amount of the token adjusted to the correct decimal places.
  
 
== Example ==
 
== Example ==
 
 
<pre>
 
<pre>
ui console view
+
log("Formatted Binance Coin Balance: {$formatted balance("BinanceSmartChain", "BNB", "100000000000000000")}")
config defi wallet("your private key here")
+
log("Proper token amount: {$get proper token amount("BinanceSmartChain","0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c","50000000000000000000")}")
+
 
</pre>
 
</pre>
  
Make sure to replace "your private key here" with your actual private key. Private keys are sensitive information that needs to be handled securely.
+
The output of this function will be the amount of the token, placed accurately on the decimal point.
  
The output of this script will display the amount of the specified token (given by the ID "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c" on the Binance Smart Chain) adjusted for appropriate decimal placement. The output might look something like this:
+
Example Output:
 
<blockquote>
 
<blockquote>
Proper token amount: 50.0
+
<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.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox