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:
My token metadata:
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.