A very simple Solidity smart contract for learning and testing purposes. The contract lets a user guess which playing card suit is marked as the “best” one.
There are no constructor parameters, no ETH involved, and no storage changes — just a pure on-chain logic check.
- Written in Solidity ^0.8.0
- Deployed with no inputs
- Uses an
enumto represent card suits - Returns
trueorfalsewhen a guess is made
The contract uses the following numeric mapping:
| Number | Suit |
|---|---|
| 0 | Clubs |
| 1 | Diamonds |
| 2 | Hearts |
| 3 | Spades |
The “best” (winning) suit is Spades (3).
Suit private constant BEST_SUIT = Suit.Spades;-
A user calls the
guessSuitfunction. -
The user passes a number between
0and3. -
The function checks if the guess matches the fixed suit.
-
The function returns:
true→ correct guessfalse→ incorrect guess
If the number is outside the valid range, the transaction reverts.
function guessSuit(uint8 suitIndex) external pure returns (bool)Parameters
suitIndex— A number from0to3
Returns
trueif the guessed suit matches the best suitfalseotherwise
You can deploy this contract using:
- Remix IDE
- Hardhat
- Foundry
There are no constructor arguments to provide during deployment.
- Open Remix
- Create
GuessTheSuit.sol - Paste the contract code
- Compile with version
0.8.x - Deploy
- Call
guessSuit(3)→ returnstrue
- The best suit is hard-coded
- No state is saved
- No players or rewards are tracked
- This contract is intended for learning and demos only