TL;DR: We’ll be running an NFT auction demo for the Hedera community in the next few months at www.hedera.auction. All code will be available on open source, and more can be heard in April's Hedera Virtual Meetup.
Like every open-source demo, the Hedera NFT auction started with an idea:
"Leemon has some special HBAR silver/gold coins. We want to tokenize one of them (Leemon will stamp it) as an NFT on HTS, then we want to run an auction on HCS for people to be able to bid on the coin in fiat or hbars. All proceeds will go to charity. How hard would it be to build this as a semi-serious demo app so we can use it with the community?"
Shortly followed by:
"Leemon is going to announce it tomorrow on the townhall as far as creating the NFT."
The only possible response I could have was:
"Better get our skates on then!!!"
It turns out that designing an open, fair, and transparent auction is not as simple as collecting bids and declaring a winner. Who knew?
The question really became, how can we create a decentralized eBay that remains affordable, environmentally friendly, and fast?
Our product requirements
After research and discussions with Paul Madsen, Tim McHale, and Leemon Baird we had a plan and our design requirements – create a Hedera token auction that was: anonymous, non-repudiable, and decentralized.
Anonymous meaning that no prior registration to take part in the auction would be required, anyone with a mainnet Hedera account should be able to place bids.
Non-repudiable meaning that once a winning bid is placed and the winner declared, the winner cannot rescind their bid.
Decentralized meaning no single authority could control the auction once started, for this we decided to run a permissioned application network using Hedera Consensus Service. By using the public ledger anyone is able to verify the auction's proceedings.
While a smart contract could be used to manage the bidding process, it would not scale well and, for some low-value auction items, prove to be too expensive, we wanted to find a practical alternative.
This ultimately manifests into the following, which we'll explain in more detail:
Each site runs the same application logic and uses Hedera Consensus Service to stay in sync with the latest auction. A Hedera account jointly owned by each site manages the bids and token transfer.
This allows for an auction that's:
Open; accessible by multiple websites operated by separate parties.
Transparent; able to be publicly monitored and verified.
Pseudonymous; requiring only a Hedera account to participate.
Affordable; costing ~$0.0001 to bid and transfer the token to the winner.
Creating our NFT
Our NFT on Hedera will be created using Hedera Token Service. In our case, the NFT is a digital representation and proof of authenticity for Leemon's physical coin.
Currently, to mint our NFT we'll:
Create an immutable file with Hedera File Service. This file contains an image related to the token and some additional properties (or metadata).
Create the actual token using Hedera Token Service with the token's symbol contains the File Id and the token itself is set to be immutable so that these details cannot be altered in time.
The auction consists of 3 Hedera components:
Hedera Token Service
Hedera Consensus Service
Hedera account for auction bids and token distribution
A Hedera account is created for each auction. This account is created with a threshold key meaning that several signatures are required to operate the account, no single party has control over the account.
The owner of the token being auctioned transfers the token to the Auction account such that when the auction is complete, the token's owner cannot refuse to transfer the token (in the event the winning bid is too low for example).
Hedera Consensus Service for auction state
The state of an auction – is a new item available? – is managed with Hedera Consensus Service. To do so, the group of sites agrees to use a Hedera Topic and a message schema.
A message containing the Token Id, Account Id, and details of the auction such as its end date, reserve price, etc.… is sent to the HCS Topic we created earlier in JSON form so that it can be read by anyone. This results in an immutable public record of the auction's details as well as the token being auctioned and the account running the auction.
Bids are placed using hbars. Each time a user places a bid via a browser extension or wallet it’s sent to a Hedera account managed by the permissioned network participants. Each auction has its own account to ensure that the bidder has sufficient funds to cover the winning bid and prevents bidders with no intention of paying at the end of the auction from placing bids in the first place.
Once a higher amount has beaten a bid, the now-losing bid is automatically refunded.
Note: Do not attempt to transfer directly from an exchange account, as they would receive eventual refunds.
Subject to installing a browser plugin to sign transactions, bidders may place bids within the web page but will also be able to do so from their wallet application.
Running an auction
The auction nodes start by monitoring the Hedera topic and create a new auction instance whenever a new message containing details of an auction arrives.
Once a new message is detected, the sites first check to see if the token being auctioned has been transferred to the related auction Hedera account, if so the auction is opened. If not, the auction nodes will wait until the ownership of the token is transferred, then start the auction. This enables the auction to support multiple items being auctioned off at the same time.
While the auction is running, each application watches bids sent into the Hedera account for that auction instance. For each bid, the applications perform several checks such as:
Is the auction still active?
Is the bid above reserve?
Is the bid increase greater than the required minimum?
Optionally, is the bidder already the current winning bid?
In the event the application determines the bid not to be the new winning bid, it will issue a refund back to the bidder using a scheduled transaction. Other applications associated with the auction account reaching the same conclusion will do the same, resulting in a crypto transfer back to the bidder. If a new high bid is received, the current winner is refunded using the same procedure.
The Hedera mainnet will collect scheduled transactions from the applications and, when enough signatures are received as indicated by the Threshold key on the account, the mainnet consensus nodes will automatically process the refund transaction.
Once the auction is closed (this is determined by comparing the consensus timestamp of transactions on the Hedera mainnet against the end date of the auction), the auction applications that participate in refunds will transfer the token (which is held by the auction account) to the winner's account by creating another scheduled transaction for the transfer in the same manner refunds were processed earlier.
As the auction takes place entirely on-ledger anyone can monitor what's happening. Are the applications acting as intended? Did the winner receive their NFT? The beauty of Hedera being a public ledger is you only need to know the Topic Id. In the demo code, we'll also provide an auction monitoring application code that can be run to watch the auction.
It is worth noting that, while this auction is more decentralized than eBay, given it is a permissioned network using a threshold key there are still points of control by few parties. The public transparency of the auction does give clarity to its participants alongside some immutable rules within which the auction operates, but the question becomes how could, or does this need be improved? For instance, could the auction members have staked hbar controlled by another threshold account managed by monitoring apps?
The good news is, like everything that Hedera creates the code is open source and available for the community to take and enhance.
A live NFT auction
To have some fun and help educate the community on Hedera we'll be running an auction of two physical hbar coins of Leemon's next couple of months.
For this auction, Hedera will invite external participants to participate in running applications and managing a key for the Hedera threshold account to ensure no one party is in control of the auction.
We’re excited for the community to see how using Hedera network services can create more fair and transparent auctions, and hope you are, too. Once we're ready, the auction will be hosted at www.hedera.auction. Learn more in our monthly virtual meetup and stay tuned by signing up for our email newsletter or following @hedera on Twitter.