Friendly token amount

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
(Example)
 
(4 intermediate revisions by one user not shown)
Line 1: Line 1:
'''$defi token amount''' is a function that converts the amount of a token into a string representation with the decimal in the correct place.
+
'''$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 is particularly beneficial for enterprise users who frequently manipulate various tokens on either the Avalanche or Binance Smart Chain blockchains.
+
When the blockchain records numbers, it does so in a format that is difficult to interpret at a glance.  
  
== User Level ==
+
For most UBot Studio commands and functions, these numbers will be automatically converted into readable numbers.
  
This function is exclusively available for enterprise users.
+
However, if you're working with low level smart contract functions, you may need to manually convert these numbers.
  
 
== Parameters ==
 
== Parameters ==
  
'''Chain:''' The blockchain where the token of interest is located. You can choose either "Avalanche" or "BinanceSmartChain".  
+
'''Chain:''' The blockchain where the token resides.
  
'''Token ID:''' This is the identifier for the token you are interested in.
+
'''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 amount of the token you want to convert.
+
'''Amount:''' The raw amount of the token that you want to format.
  
== Return Value ==  
+
== Return Value ==
  
This function returns a string value which is the representation of the given token amount with the decimal in the correct place.
+
This function returns the friendly amount of the given token from the raw input amount.
  
 
== Example ==
 
== Example ==
  
 
<pre>
 
<pre>
set(#my token amount, $defi token amount("BinanceSmartChain", "BNB", "1000000000000000000"), "Global")
+
ui console view
ui text msg("Your BNB token amount with the correct decimal placement is: {#my token amount}")
+
config defi wallet("your private key")
 +
log("DAI Friendly Amount: {$friendly token amount("BinanceSmartChain", "DAI", "1000000000000000000")}")
 
</pre>
 
</pre>
  
In this example, the script is calculating the correct decimal placement for the BNB token amount "1000000000000000000" on the Binance Smart Chain and then displaying the converted value in the UI.
+
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:
 +
 
 +
<blockquote>
 +
<p>DAI Friendly Amount: 1</p>
 +
</blockquote>

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