Friendly token amount

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
(Example)
 
(3 intermediate revisions by one user not shown)
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.  
+
'''$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.
  
 
== Parameters ==
 
== Parameters ==
  
'''Chain:''' The blockchain network chain associated with the token. Available options include Avalanche and Binance Smart Chain.
+
'''Chain:''' The blockchain where the token resides.
  
'''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 you want to work with. This can be the symbol of the token, or it can be the contract address.
  
'''Amount:''' The raw quantity of the specified token that needs to be adjusted for decimals.
+
'''Amount:''' The raw amount of the token that you want to format.
  
 
== 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 the friendly amount of the given token from the raw input amount.
  
 
== Example ==
 
== Example ==
  
 
<pre>
 
<pre>
ui console view  
+
ui console view
config defi wallet("your private key here")
+
config defi wallet("your private key")
log("Proper token amount: {$get proper token amount("BinanceSmartChain","0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c","50000000000000000000")}")
+
log("DAI Friendly Amount: {$friendly token amount("BinanceSmartChain", "DAI", "1000000000000000000")}")
 
</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.
+
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:
  
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:
 
 
<blockquote>
 
<blockquote>
Proper token amount: 50.0
+
<p>DAI Friendly Amount: 1</p>
 
</blockquote>
 
</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