1

I am doing a decentralized market of tokens ERC 721 and I have the problem that if two people give to buy the token at the same time, I do not know what would happen.

Is there any way, without spending gas, to know if there is someone in the period of purchase of that token? Since it would be paid with FIAT money, once it receives the payment, it would call the transfer function. So I have the problem that if the two transfers are made in the same block, I do not know which of the two would be made. I have tried to set a variable that changes to HOLD while someone is in the buying process, but it would cost gas. It could be done from the server side, a queue for the purchase, but I would like to do it from the smart contract part directly.

In this question, someone says that all requests would be made and the last one would persist. But in my case, being a transaction, the first one who does it takes the token and the second one no longer has a token to receive.

  • Short answer: One one transaction will succeed. – xpepermint Jan 3 at 5:29
1

This is basically why various marketplaces (and exchanges) require X amount of confirmations before accepting a transfer.

As I see it, you can't avoid some checks from your backend system. When someone sends you fiat, you should send a tx to the contract saying "transfer initiated for X tokens to user Y". When you have received X confirmations for that block, if there are no competing purchases you should issue another tx "complete the transaction".

It would not be ideal (speed-wise) but it would be fool-proof: wait for X confirmations (X blocks to be mined on top of the block you're interested in) and only then declare the final result.

Someone else might have some more speedy ideas.

  • In this case, would there be a gas expense to do the first check and once it has been validated, another gas expense to make the final transaction? – Ivan Garcia Apr 4 '18 at 10:59
  • I was rethinking your solution a bit - edited my answer to include details how you could verify that there are no competing purchases. – Lauri Peltonen Apr 4 '18 at 11:05

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.