1

I want to build an auctions contract and I'm very aware of the push-pull pattern for auctions or sending Ether but beyond that I wanted to explore if there was a way where I could send back the money, or whatever is being sent to the user, automatically. What I'm trying to solve with this is that if I want to run multiple auctions at a time and the same user bids on all of them it can be very tedious for them to claim back all their bids manually, I've been trying to study what OpenSea does but I've not had much success there.

I wanted to use a token (DAI or WEI) but I'm not sure if they are subject to the same risks as sending Eth automatically through a loop or something.

So, what are my options here or what's a popular approach these pages that run auctions take for users to make bids and whatnot?

1

Ideally you should never send ether in a loop (well, ideally you should avoid loops at all cost). If you do so, you'll have to execute the function with a lot of gas, check the gas left in every iteration of the loop, and probably to execute the same function multiple times until all your users have received all the funds. In other words: it's not scalable, and I doubt you can get any profit out of it if you pay so many fees.

So, what are my options here or what's a popular approach these pages that run auctions take for users to make bids and whatnot?

The ideal solution would be that users can deposit funds in the contract, and those funds belong to them as long as they do not buy any items in those auctions. Whenever they do, the balance will be updated accordingly. This way there will be a balance mapping like mapping(address => uint) and at any given point in time an user can get all his funds back very easily.

I wanted to use a token (DAI or WEI) but I'm not sure if they are subject to the same risks as sending Eth automatically through a loop or something.

Yes, sending tokens is even more expensive than sending ether, generally. Dealing with tokens instead of ether makes the logic way more complicated too, which definitely is the last thing you'd want in a smart contract. With this I'm not saying it's a bad idea to use tokens, it depends on your needs. I'm just warning about the extra difficulties.

| improve this answer | |
  • So basically my option is to use the withdrawal pattern which is what you mention on your second paragraph? OpenSea uses WETH, do you know the benefit of this or maybe you have a better understanding of their auctions system? The risk I was mentioning about looping and sending funds is basically causing the function to revert because of a malicious address bidding on the auction but I get your point about it not being a good idea besides that concern. – Aguxez Oct 29 '19 at 1:21
  • 1
    wETH is just an ERC20 wrapper around ETH so that you can transfer everything as a token, useful when you don't want to have different logics for ERC20 and ether in your smart contracts. You could use it if you plan to support many tokens, otherwise I wouldn't recommend it since it's more expensive in gas and harder to deal with. And yes, I recommend you the withdraw pattern I mentioned. – Molina Oct 29 '19 at 1:38

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.