Friendly token amount

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
(Created page with "'''$get token amount''' is a function that returns an amount of a specific token with the decimal in the correct place. It is important because cryptocurrencies often have d...")
 
(Example)
 
(5 intermediate revisions by one user not shown)
Line 1: Line 1:
'''$get token amount''' is a function that returns an amount of a specific token 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.
  
It is important because cryptocurrencies often have different decimal places - for example, Ether has 18 decimal places.
+
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 blockchain network (such as Avalanche or BinanceSmartChain) where the token resides.
+
'''Chain:''' The blockchain where the token resides.
  
'''Token ID:''' The token for which you want to get the amount with the right decimal places. You can select from the dropdown list or manually enter the contract address if your desired token isn't listed.
+
'''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 you want to convert to the correct decimal places.
+
'''Amount:''' The raw amount of the token that you want to format.
  
== Return Value ==  
+
== Return Value ==
  
This function returns a string that represents the correctly formatted amount of the specified token.
+
This function returns the friendly amount of the given token from the raw input amount.
  
 
== Example ==
 
== Example ==
  
 
<pre>
 
<pre>
log("Correctly formatted token amount: {$get token amount("Avalanche", "AVAX", "1000000000000000000")}")
+
ui console view
 +
config defi wallet("your private key")
 +
log("DAI Friendly Amount: {$friendly token amount("BinanceSmartChain", "DAI", "1000000000000000000")}")
 
</pre>
 
</pre>
  
The above script logs the correctly formatted amount of AVAX for the raw amount of "1000000000000000000" on the Avalanche blockchain. For an AVAX amount of "1000000000000000000" raw units, the correct amount would be "1" AVAX because AVAX has 18 decimal places, similar to Ether.
+
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.
  
**Please note:**
+
This example command will take the raw amount "1000000000000000000" for DAI token on Binance Smart Chain and return a friendly output:
  
Be sure to correctly input the raw amount, as it directly affects the result. Misinterpretation of the raw amount can lead to significant discrepancies in the resulting value.
+
<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