0

How can I send a nat value to a contract that represents a data type which is not a whole number?

For example, the xtzToToken entrypoint of the tzBTC contract allows a user to call the xtzToToken entrypoint and send an argument of nat minTokensBought. If I want to send a value that is between 1 and 0 for this argument, how would I do so>

Here is what I've tried (unsuccessfully) via the tezos=client:

tezos-client --dry-run transfer 10000 from alice to KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5 \
                --entrypoint xtzToToken \
                --arg '(Pair "tz1eYpX4e1nu7e3cvtF7UvKFqUvWDahte1ot" (Pair 1/2 "2021-09-01T09:57:00Z"))' \
                --burn-cap 999

and

tezos-client --dry-run transfer 10000 from alice to KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5 \
                --entrypoint xtzToToken \
                --arg '(Pair "tz1eYpX4e1nu7e3cvtF7UvKFqUvWDahte1ot" (Pair 0.5 "2021-09-01T09:57:00Z"))' \
                --burn-cap 999 
2

Its not possible to send lower than 1 mutez. nat is also required to be a whole number.

Tezos/XTZ has 6 decimal places. When a user sees "1 XTZ" in an app, that is represented as 1000000 on the blockchain (6 zeros for 6 decimal places). The blockchain and RPC deal in this smaller scale (called mutez) and its up to each application to scale it up to XTZ when displaying to a user.

It is the same for all tokens. tzBTC has 8 decimal places, so 1 tzBTC, is made up of 100000000 satoshi's.

When you are doing this:

(Pair 1 "2021-09-01T09:57:00Z")

you are not sending 1 XTZ, you are sending 1 mutez (1/1000000 of an XTZ). Sending 1 XTZ would look like this:

(Pair 1000000 "2021-09-01T09:57:00Z")
3
  • So if I want to send a .62 value for minTokensBought to the addLiquidity entrypoint, I would send a value of (.62 * 100000000) or 62000000? Also, how can I look at a contracts code on an explorer like tzkt.io to see the amount of decimal places that token uses?
    – Whirlybird
    Jul 30 at 10:46
  • Also it may be worth calling out that the argument I'm passing isn't a value for tzBTC, it's a value for the LQT token found here: granadanet.tzkt.io/KT1AafHA1C1vk959wvHWBispY9Y2f3fxBUUo/…
    – Whirlybird
    Jul 30 at 10:50
  • @Whirlybird Fa1.2 tokens have no standard way to record decimal places, typically you check their website. FA2 contracts have a metadata field thats stored offchain and holds this info. The Better Call dev explorer manually indexes token data. If you search for a contract and click on the "Tokens" tab you can see the metadata. Here for example is Ethtz, where you can see that it has 18 decimal places: better-call.dev/mainnet/KT19at7rQUvyjxnZ2fBv7D9zc8rkyG7gAoU8/… Jul 30 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.