Friendly token amount

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
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.
+
  
 
== 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")}")
+
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.
+
The function is very useful because some tokens have different levels of precision, and it's easy to get confused with the amount when the token has high precision. Always make sure to verify the amount before performing transactions on any blockchain.

Revision as of 20:03, 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.

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.

Return Value

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

Example

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

The function is very useful because some tokens have different levels of precision, and it's easy to get confused with the amount when the token has high precision. Always make sure to verify the amount before performing transactions on any blockchain.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox