Ask Your Question

Getting 10% of tez

asked 2017-05-13 15:56:58 -0500

laprunminta gravatar image

Hi, I'm writing a smart contract in Michelson, and I can't figure out how to get 10% of a tez amount. According to the language.pdf doc on Michelson, there are only these operators on tez: ADD, SUB, MUL, and COMPARE.

  • ADD: :: tez : tez : 'S -> tez : 'S
  • SUB: :: tez : tez : 'S -> tez : 'S
  • MUL :: tez : u?int{8|16|32|64} : 'S -> tez : 'S
  • COMPARE: :: tez : tez : 'S -> int64 : 'S

So it looks like I want to use MUL on a stack that looks like [ tez : 0.10], but 0.10 isn't an int, so I can't use that.

If I try to do MUL [tez : tez] where the second tez is "0.10", I get "operator MUL is undefined between tez and tez"

I saw that DIV existed as well, but if I do DIV [tez: tez], I get "operator DIV is undefined between tez and tez"

If I do DIV [tez: uint32] I get "operator DIV is undefined between tez and uint32"

It looks like the only thing I can do is:

PUSH uint32 10; PUSH uint32 1; DIV;

But that seems pretty convoluted, and I'm pretty sure that the result of int division should only be an int.

Any help would be appreciated, thanks!

edit retag flag offensive close delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-05-13 23:11:39 -0500

tezos gravatar image

updated 2017-05-13 23:25:20 -0500

Yes, it's totally missing, thank you for noticing! We're redoing the integers to use libgmp everywhere; tere will be only three int types: int, nat, and tez. But before we do we should still fix this.

If you're feeling adventurous and want to send us a patch, take a look at Mul_tez in the code

You can add Div_tez is a couple lines by replicating this pattern.

edit flag offensive delete publish link more


Cool! I'll look into sending a patch. Thanks for the response!

laprunminta ( 2017-05-13 23:28:01 -0500 )edit
Login/Signup to Answer

Question tools

1 follower


Asked: 2017-05-13 15:56:58 -0500

Seen: 13,711 times

Last updated: May 13 '17