https://github.com/cecile-hirschauer/wishlist_dapp
https://github.com/cecile-hirschauer/wishlist_dapp
dapp etherjs hardhat nextjs rainbowkit shadcnui smart-contracts solidity tailwindcss viem wagmi
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/cecile-hirschauer/wishlist_dapp
- Owner: Cecile-Hirschauer
- Created: 2024-05-17T14:04:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-19T15:30:31.000Z (over 1 year ago)
- Last Synced: 2025-02-01T03:44:26.736Z (8 months ago)
- Topics: dapp, etherjs, hardhat, nextjs, rainbowkit, shadcnui, smart-contracts, solidity, tailwindcss, viem, wagmi
- Language: JavaScript
- Homepage:
- Size: 373 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Wishlist Smart Contract
This repository contains the code for the Wishlist smart contract. This contract allows users to manage a wishlist of items they want to buy and allows others to buy items from these wishlists.
## Overview
The Wishlist contract allows users to:
- Add items to their wishlist.
- View the items on their wishlist.
- Buy items from other users' wishlists.## Contract Details
### Contract: `Wishlist`
#### Structs
- **Item**
- `uint256 id`: The unique identifier of the item.
- `string name`: The name of the item.
- `uint256 price`: The price of the item in wei.
- `bool bought`: Whether the item has been bought.
- `address boughtBy`: The address of the user who bought the item, if any.#### State Variables
- `uint256 public nextId`: The next id to be assigned to a new item.
- `mapping(address => Item[]) private wishlist`: The wishlist of items for each user.#### Functions
- `getWishlist(address _of) external view returns (Item[] memory)`: Returns the wishlist of a specific user.
- `addToWishlist(string calldata _name, uint256 _price) external`: Adds a new item to the wishlist of the sender.
- `buyItem(address _for, uint256 _id) external payable`: Allows a user to buy an item from someone else's wishlist.### Errors
- `NotEnoughFounds()`: Thrown when the provided funds are not enough to buy an item.
- `AlreadyBought()`: Thrown when an attempt is made to buy an item that has already been bought.### Test Coverage
#### Version
> solidity-coverage: v0.8.12
#### Instrumenting for coverage...
> Wishlist.sol
#### Compilation:
Compiled 1 Solidity file successfully (evm target: paris).
#### Network Info
> HardhatEVM: v2.22.4
> network: hardhat#### Deployment
1. [x] should deploy the smart contract
2. [x] addToWishList
3. [x] should add an element in the wishList#### buyItem
1. [x] should NOT buy item if not enough funds are provided
2. [x] should buy the item if enough funds are provided
3. [x] should NOT buy the item if the item has already been bought5 passing (151ms)
---------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
---------------|----------|----------|----------|----------|----------------|
contracts/ | 100 | 75 | 100 | 100 | |
Wishlist.sol | 100 | 75 | 100 | 100 | |
---------------|----------|----------|----------|----------|----------------|
All files | 100 | 75 | 100 | 100 | |
---------------|----------|----------|----------|----------|----------------|### Deployment
To deploy the Wishlist smart contract with local node, use the following command:
```sh
npx hardhat ignition deploy ./ignition/modules/Wishlist.js --network localhost