In Solidity, we introduce the concept of states, to express variables (used to store information) declared inside of the contract scope and outside of the function scope, similar to the global variable concept in other programming languages. They represent values that are permanently stored in contract storage (on the blockchain); hence, the contract knows their updated values. In general, a state variable in Solidity is declared as follows:
<Variable type> <visibility specifier> <variable name>
In this contract, we'll need to define a set of variables, as follows:
- auction_owner: This is an address variable that is used to store the vehicle vendor, who is also the auction's owner. This address is where the winning bid goes after the auction ends.
- auction_end and auction_start: These represent the auction's start and end epoch times, respectively.
- highestBid: This represents the highest amount bid in ether.
- highestBidder: This represents the Ethereum address of the highest bidder.
- bidders: This is an array of all bidder addresses.
- Bids: This is a mapping, matching the address of each bidder with their total bid.
- STATE: This represents the auction state, whether it is open or closed (cancelled).