English Auction | Solidity 0.8
Вставка
- Опубліковано 5 жов 2024
- Solidity application example - English auction.
0:11 - State variables
2:34 - Constructor
3:50 - Start
5:47 - Bid
8:34 - Withdraw
10:13 - End
13:49 - Demo
#Solidity #SmartContract #Ethereum #スマートコントラクト
Remix
remix.ethereum...
Code
solidity-by-ex...
Take a course
www.smartcontr...
Follow
/ programmersmart
/ discord
t.me/smartcont...
smartcontractp...
gave me a chuckle when you pointed out 100 years should be enough time for an auction. Really puts your limited time on this earth in perspective!
Gone in 60 seconds
0:11 - State variables
2:34 - Constructor
3:50 - Start
5:47 - Bid
8:34 - Withdraw
10:13 - End
13:49 - Demo
Great video! One questions about the bidding system. I think the contract has one flaw - the bidders would have to constantly withdraw in order to take their bids out, so they can e.g. still outbid another person. One solution to this was to adjust the UI, so if person A bids with msg.value set to 1ETH, then person B bids with msg.value set to 1.1ETH, the person A to outbid would have to do another bid with msg.value set to e.g. 0.2ETH (so 1.2ETH total).
I adjusted my code to immediately send back the previous high bid. And then simply ensure that all bids exceed the current bid. In this way, no money is being held onto during the auction. If not, every bidder's funds are locked up for the duration of the auction.
I hope I understood your question properly and that this reply makes sense!
@@rickfarina9835 This sounds like the contract could be vulnerable to Denial of Service attacks by having funds pushed back to sender's wallets, rather than pulled back from the sender themself. Would like to know what you have implemented to mitigate this attack vector. Basically an external contract could place a bid at an auction, without a fallback function allowing for ETH to be received. When someone outbids the price and your contract attempts to push back funds, it would throw an error, potentially preventing further execution of code necessary for the auction to continue to function.
@@only_trades One way to prevent DOS is to allow users to withdraw their funds instead of sending it, i think that what this contract does, correct me if wrong...
@@SmartDevs Yea you are correct. thats what I did
Learning so much. Thank you for the videos!
Amazing! Thanks
Learning so much from this playlist, thanks!
Love it! Thanks for creating.
Sir i really like and notice everytime, when you say "Constractor" the "tor" part is really amazin and i love it. Hahahaha
What if we use approve instead of transferFrom. That way we don’t have to send the NFT back and forth between the seller and the contract if there isn’t any bidder?
Also, since the contract address have the approval from the seller, it can transfer the NFT to the auction winner on behalf of the seller.
Edit: on second thought, using approve feels less transparent, since the seller doesn’t commit his NFT to the auction contract and he can revoke approval anytime.
Also using approve in the start() function won’t work either. msg.sender will be the auction contract, not the account that initiates start()
constractor at 2:37 i love it
One question please, what information the Event Start()/emit Start() will log ? Is it a must?
If I understand correctly, you could bid 1, 2, and 3 ether and be outbid by someone bidding 4 ether, and you have now transferred 1+2+3=6 ether into the contract, which seems capital inefficient to say the least. I realize this is just an introduction contract, I suppose you could make it to where you just send in 1 ether on your second bid and then 1 more ether on your third bid, but the complexity of the contract would increase and it would use more (not much more?) gas
A simple fix is to have a another contract that calls withdraw and then bid.
Example
withdraw 2, bid 3
Great work again!
great demo loved it
Informative
thanks man. this is so helpful...
Great vid! Could you please create a video on assembly and yul? Just the basics. I was trying to learn it from the documentation but it is so complex. Thanks a lot!
I am just as clueless as you. Hard to learn without a practical example
wonderful
On line 41, endAt=uint32(block.timestamp + 60), there would be a problem deploying this after 2038, right? You'd need more than 32 bits at that point, and you're truncating the upper bits. Minor issue I suppose!
fantastic
I guess this is completely on chain, isnt open sea english auction using both on chain and off chain ?
after the auction is completed successfully, i click on end, but i get the below error : transact to Auction.end errored: VM error: revert.
revert
The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
Debug the transaction to get more information.
Thank you for the videos. I've a small confusion in "end function", that why did you use the transferFrom and didn't use the transfer since the tokens are already in the contract?
transfer is not part of ERC721 functions
I want to build a factory smart contract that creates instances of the auction smart contract, can you show me an example of factory contract?
solidity-by-example.org/new-contract/
Also look into minimal proxy / clone by OpenZeppelin
good auction demo
just wonder 1 day blockchain can run cronjob or delay function
you are not getting money for the NFT in the bid function, someone can just bid for it and get it for free while the contract would be the one to pay for it if it even has money for that.
Get it for free?
But there is a check inside the bid function
require(msg.value > highestBid, "value < highest");
highestBid is initialized with _startingBid inside the constructor
I meant something else but this was my 1-2 day of solidity so I guess I didn't understand the msg.value and payable function so it's my bad. I thought that since you are not explicitly transferring the amount sent to the contract, that the guy can just add a msg.value that is higher than the bid but not have to pay for it since there is no functionality to take the token but obviously I was wrong since the function is payable so i was wrong@@smartcontractprogrammer
now Im already finished with solidity 0.8 and halfway through hack solidity so Im getting better ;) I also commented the delegatecall part 2 video on the hack solidity, you can check my comment out there
hello, I have a question. When we deploy contract we assign nftId and seller one time and it cant be changed, so we can do only 1 auction with 1 seller and 1 nft, right? If someone else want use your auction he cant, because contract was deployed with constant seller and nftId? it cant be redeployed each time when someone want to create a new auction?
How do you think why a transaction is stuck after I started an auction, made some bigs from different accounts before an auction is ended and then another bid after an auction is ended? If I call end() after all bids are made without making another bid after an auction is ended so its ok.
hello, in what order would you sugest watching your playlists?
difficulty is mostly from oldest to newest video
Solidity 0.8
Hack Solidity
Should we not use call instead of transfer?
Yes - transfer was used to keep this code and video shorter
please the code of NFT.sol where can i find it
solidity-by-example.org/app/erc721
1080p?
9:30 rerntramcy
Can you publish the NFT.sol, thank you!
solidity-by-example.org/app/erc721/
@@smartcontractprogrammer Thx!
Does not a uint32 cost more gas than a uint256?
Maybe
@@smartcontractprogrammer why?!
@Anon Decen Thanks
At minute 5:33, you transfer ownership from seller to the auction contract. Shouldn't this instead be to simply "approve" the contract to transfer the token on the seller's behalf as shown here?
nft.approve(address(this), nftId) // on a function where msg.sender is the seller.
Thanks!
Seller can change approval and ownership during the auction.
By transferring ownership to the contract, the seller doesn't have control of the NFT during the auction
@@smartcontractprogrammer Ok, I see you're thinking on this... They could otherwise sell it off in the middle of the auction. Makes sense. Thanks @Smart Contract Programmer !! And Great Videos!!
Shouldn't there be a require verification of msg.sender != highestBidder when they withdraw fund?
bids store the total of previous highest bids, so the current highest bid is not included