0

So, i'm doing the royalties function for my NFT Marketplace. My idea was to make a big map with the royalties (user and amount) for each new token created, and it's working fine. My problem is when i'm trying to buy a item, it's gives me this error:

TezosOperationError: (branch) proto.017-PtNairob.contract.empty_transaction

My buy function was working fine until i add the royalties function. Here is the buy entrypoint:

@sp.entry_point
def buy(self, params):
    
    k = sp.local('k', 0)
    sp.for i in self.data.data[params.token_id]:
        sp.if k.value < params.quant:
            sp.if params.seller == i.holder:
                sp.if params.price == i.amount:
                    i.holder = sp.sender
                    i.collectable = False
                    k.value += 1
    price = sp.utils.mutez_to_nat(params.price)
    total_price = params.quant * price
    

    self.fa2_transfer(self.data.token, params.seller, sp.sender, params.token_id, params.quant)
    
    total_royal = sp.local('total_royal', 0)
    sp.for g in self.data.royalties[params.token_id]:
        
        royal_to_send = total_price * (g.amount / 1000)
        
        total_royal.value += royal_to_send

        royal_to_send = sp.utils.nat_to_mutez(royal_to_send)

        sp.send(g.address, royal_to_send)
    
    
    total_price -= total_royal.value
    total_price = sp.as_nat(total_price)
    total_price = sp.utils.nat_to_mutez(total_price)
    
    sp.send(params.seller, sp.split_tokens(total_price, 90, 100))

My royalties metadata:

https://api.ghostnet.tzkt.io/v1/contracts/KT1JJf89Vmy3w3j5d5oq6TmGSucbXr3iQ5eN/bigmaps/royalties/keys

My token metadata:

https://api.ghostnet.tzkt.io/v1/contracts/KT1JJf89Vmy3w3j5d5oq6TmGSucbXr3iQ5eN/bigmaps/data/keys

=== Update

I discovered this line "sp.send(g.address, royal_to_send)" is giving error (i removed it and the transaction goes fine), but i can't find why and a solution about it. By doing some tests it's clear the address is working, but amount not. I defined amount with sp.TNat because it is a normal number.

2 Answers 2

0

empty_transaction occurs when you're sending 0 mutez with no data. That's the case when you do sp.send(receiver, sp.mutez(0)).

Your last line is probably equivalent to that in some / all cases.

You should not use nat_to_mutez or nat_to_tez as you can use the mutez type everywhere. I would start by fixing this last point before trying to fix your other problem.

2
  • Thanks for the awnser, i understand what you saying, but when i do something like this: royal_to_send = g.amount / sp.mutez(1000) results in a nat number, not a mutez number (g.amount is mutez) Commented Oct 3, 2023 at 15:15
  • Instead of royal_to_send = total_price * (g.amount / 1000) you can do royal_to_send = sp.split_tokens(total_price, g.amount, 1000). You can remove every sp.nat_to_mutez.
    – Jordan_tez
    Commented Oct 4, 2023 at 17:44
0

I found the issue. The problem isn't the nat_to_mutez, but this: royal_to_send = total_price * (g.amount / 1000). g.amount / 1000 always return a float number, so, i don't know what happens in blockchain (because it don't accept float numbers), but, doing first total_price * g.amount, and after so, dividing by 1000 will work fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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