Friendly token amount

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
(Example)
 
(2 intermediate revisions by one user not shown)
Line 1: Line 1:
'''$formatted balance''' is a function that allows you to get the amount of a token with the decimal placed accurately.  
+
'''$friendly token amount''' is a function that returns an amount of a given token formatted with the decimal in the correct place. It is based on the token's decimals value defined in its contract.
  
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.
+
When the blockchain records numbers, it does so in a format that is difficult to interpret at a glance.
 +
 
 +
For most UBot Studio commands and functions, these numbers will be automatically converted into readable numbers.
 +
 
 +
However, if you're working with low level smart contract functions, you may need to manually convert these numbers.
  
 
== Parameters ==
 
== Parameters ==
  
'''Chain:''' The specified blockchain chain where the token exists. The available options are "Avalanche" or "BinanceSmartChain".
+
'''Chain:''' The blockchain where the token resides.
  
'''Token ID:''' The token for which the formatted balance must be calculated.
+
'''Token ID:''' The token you want to work with. This can be the symbol of the token, or it can be the contract address.
  
'''Amount:''' The total amount of the token represented as a string.
+
'''Amount:''' The raw amount of the token that you want to format.
  
 
== Return Value ==
 
== Return Value ==
  
This function returns a string, which is the calculated amount of the token adjusted to the correct decimal places.
+
This function returns the friendly amount of the given token from the raw input amount.
  
 
== Example ==
 
== Example ==
 +
 
<pre>
 
<pre>
log("Formatted Binance Coin Balance: {$formatted balance("BinanceSmartChain", "BNB", "100000000000000000")}")
+
ui console view
 +
config defi wallet("your private key")
 +
log("DAI Friendly Amount: {$friendly token amount("BinanceSmartChain", "DAI", "1000000000000000000")}")
 
</pre>
 
</pre>
  
The output of this function will be the amount of the token, placed accurately on the decimal point.
+
Please replace "your private key" with your actual DeFi wallet's private key.
 +
 
 +
Be mindful when you are handling your private key. It's a sensitive piece of data that allows full control over your funds in your DeFi wallet. Therefore, never share this key publicly or with anyone.
 +
 
 +
This example command will take the raw amount "1000000000000000000" for DAI token on Binance Smart Chain and return a friendly output:
  
Example Output:
 
 
<blockquote>
 
<blockquote>
<p>Formatted Binance Coin Balance: 10 BNB</p>
+
<p>DAI Friendly Amount: 1</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.
 

Latest revision as of 23:58, 4 July 2023

$friendly token amount is a function that returns an amount of a given token formatted with the decimal in the correct place. It is based on the token's decimals value defined in its contract.

When the blockchain records numbers, it does so in a format that is difficult to interpret at a glance.

For most UBot Studio commands and functions, these numbers will be automatically converted into readable numbers.

However, if you're working with low level smart contract functions, you may need to manually convert these numbers.

[edit] Parameters

Chain: The blockchain where the token resides.

Token ID: The token you want to work with. This can be the symbol of the token, or it can be the contract address.

Amount: The raw amount of the token that you want to format.

[edit] Return Value

This function returns the friendly amount of the given token from the raw input amount.

[edit] Example

ui console view
config defi wallet("your private key")
log("DAI Friendly Amount: {$friendly token amount("BinanceSmartChain", "DAI", "1000000000000000000")}")

Please replace "your private key" with your actual DeFi wallet's private key.

Be mindful when you are handling your private key. It's a sensitive piece of data that allows full control over your funds in your DeFi wallet. Therefore, never share this key publicly or with anyone.

This example command will take the raw amount "1000000000000000000" for DAI token on Binance Smart Chain and return a friendly output:

DAI Friendly Amount: 1

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox