Friendly token amount

From UBot Studio
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
 
'''$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.
 
'''$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 ==
Line 29: Line 35:
 
<p>DAI Friendly Amount: 1</p>
 
<p>DAI Friendly Amount: 1</p>
 
</blockquote>
 
</blockquote>
 
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 23:57, 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.

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

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox