A smart contract is developed to support the process of decentralized auction. Decentralized auction is a kind of auction in which
the bid raised is transparent to other participants in the contest. The ethereum smart contract developed will support
the auction in raising a bid, withdrawing money from the bid and an option to end the auction. The smart contract is
built using the Truffle console
and Ganache
which are part of Truffle framework. Ganache is the personal block chain
that allows developers to create smart contracts.
Based on the Simple Open Auction.
-
Install Truffle globally.
npm install -g truffle
Also Requires Ganache to be preinstalled and running for a personal Truffle development blockchain.
-
Clone the repo.
-
Run the development console in the repo.
truffle develop
-
Compile and migrate the smart contracts. Note inside the development console we don't preface commands with
truffle
.compile migrate
-
Run the
liteserver
development server (outside the development console) for front-end hot reloading. Smart contract changes must be manually recompiled and migrated.// Serves the front-end on https://localhost:3000 npm run dev
- This payable method which is used to collect ethers is used to raise the bid in the open auction.
- In order to raise a proper bid two conditions are essentially required to be met.
- One is the auction should be still alive. Second requirement is that the newly bid value should be greater than
the already existing highest bid value. This is written as part of the
require(condition)
part. - Once a proper bid is raised, then the existing highest bidder will be sent to
pendingReturns[]
mapped with highestBidder and highestBid raised by him. - The newly bid user will now become the highest bidder and the newly bid value becomes the highestBid value.
- This method is used to withdraw/send back that are in the pendingReturns array.
- To avoid the re-entrancy attack the pendingReturns of the sender is made equal to 0 when there is some amount greater than 0 associated in returns. Otherwise, the attacker may keep on attacking until he drains the amount.
- The function returns true, if the withdrawal is successful. Otherwise it returns false.
- This method is invoked to end the auction and can be triggered only by the beneficiary.
- To make sure that the beneficiary has only triggered the auctionEnd method we have a require condition written at the beginning.
- Once the
auctionEnd()
method is invoked it cannot be called again. This is checked by the flag auctionAlive which is set to false, when once invoked.
-
How do I use this with the EthereumJS TestRPC?
It's as easy as modifying the config file! Check out our documentation on adding network configurations. Depending on the port you're using, you'll also need to update line 16 of
src/js/app.js
.