-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2116f1c
commit 8dfe61d
Showing
21 changed files
with
34,840 additions
and
3,588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
4ba20e6af0cfaca3c77085fa511b80893a48cc259d0559ee9117b50179652dc2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,15 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
# Basic Sample Hardhat Project | ||
|
||
## Getting Started | ||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. | ||
|
||
First, run the development server: | ||
Try running some of the following tasks: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
```shell | ||
npx hardhat accounts | ||
npx hardhat compile | ||
npx hardhat clean | ||
npx hardhat test | ||
npx hardhat node | ||
node scripts/sample-script.js | ||
npx hardhat help | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file. | ||
|
||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`. | ||
|
||
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file. | ||
|
||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`. | ||
|
||
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Fragment, useState } from "react"; | ||
import { Dialog, Transition } from "@headlessui/react"; | ||
|
||
export default function Modal({ nft, open = false, setOpen }) { | ||
return ( | ||
<Transition.Root show={open} as={Fragment}> | ||
<Dialog as="div" className="relative z-10" onClose={setOpen}> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0" | ||
enterTo="opacity-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
> | ||
<div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" /> | ||
</Transition.Child> | ||
|
||
<div className="fixed z-10 inset-0 overflow-y-auto"> | ||
<div className="flex items-end sm:items-center justify-center min-h-full p-4 text-center sm:p-0"> | ||
<Transition.Child | ||
as={Fragment} | ||
enter="ease-out duration-300" | ||
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" | ||
enterTo="opacity-100 translate-y-0 sm:scale-100" | ||
leave="ease-in duration-200" | ||
leaveFrom="opacity-100 translate-y-0 sm:scale-100" | ||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" | ||
> | ||
<Dialog.Panel className="relative bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:max-w-sm sm:w-full sm:p-6"> | ||
<div> | ||
<div className="mt-3 text-center sm:mt-5"> | ||
<div className="mt-2"> | ||
<p className="text-sm text-gray-500 text-ellipsis break-words"> | ||
OWNER: {nft.owner} | ||
</p> | ||
<p className="text-sm text-gray-500 text-ellipsis break-words mt-4"> | ||
SELLER: {nft.seller} | ||
</p> | ||
<p className="text-sm text-gray-500 text-ellipsis break-words mt-4"> | ||
CONTRACT: {nft.nftContract} | ||
</p> | ||
<p className="text-sm text-gray-500 text-ellipsis break-words mt-4"> | ||
TOKEN URI: {nft.tokenURI} | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="mt-5 sm:mt-6"> | ||
<button | ||
type="button" | ||
className="inline-flex justify-center w-full rounded-md border border-transparent shadow-sm px-4 py-2 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:text-sm" | ||
onClick={() => setOpen(false)} | ||
> | ||
Ok | ||
</button> | ||
</div> | ||
</Dialog.Panel> | ||
</Transition.Child> | ||
</div> | ||
</div> | ||
</Dialog> | ||
</Transition.Root> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const nftaddress = "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"; | ||
export const nftmarketaddress = "0x5FbDB2315678afecb367f032d93F642f64180aa3"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/utils/Counters.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
|
||
import "hardhat/console.sol"; | ||
|
||
contract NFT is ERC721URIStorage, ERC721Burnable { | ||
using Counters for Counters.Counter; | ||
Counters.Counter private _tokenIds; | ||
address contractAddress; | ||
|
||
constructor(address marketplaceAddress) ERC721("Gutschein Marketplace", "GM"){ | ||
contractAddress = marketplaceAddress; | ||
} | ||
|
||
function createToken(string memory tokenURII) public returns (uint){ | ||
_tokenIds.increment(); | ||
uint256 newItemId = _tokenIds.current(); | ||
|
||
_mint(msg.sender, newItemId); | ||
_setTokenURI(newItemId, tokenURII); | ||
setApprovalForAll(contractAddress, true); | ||
return newItemId; | ||
} | ||
|
||
function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) { | ||
super._burn(tokenId); | ||
} | ||
|
||
function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) { | ||
return super.tokenURI(tokenId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/utils/Counters.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | ||
|
||
import "hardhat/console.sol"; | ||
|
||
contract NFTMarketplace is ReentrancyGuard { | ||
using Counters for Counters.Counter; | ||
Counters.Counter private _itemIds; | ||
Counters.Counter private _itemsSold; | ||
|
||
address payable owner; | ||
uint256 listingPrice = 0.1 ether; | ||
|
||
constructor() { | ||
owner = payable(msg.sender); | ||
} | ||
|
||
struct MarketItem { | ||
uint itemId; | ||
address nftContract; | ||
uint256 tokenId; | ||
address payable seller; | ||
address payable owner; | ||
uint256 price; | ||
bool isRedeemed; | ||
} | ||
|
||
mapping(uint256 => MarketItem) private idToMarketItem; | ||
|
||
event MarketItemCreated ( | ||
uint indexed itemId, | ||
address indexed nftContract, | ||
uint256 indexed tokenId, | ||
address seller, | ||
address owner, | ||
uint256 price, | ||
bool isRedeemed | ||
); | ||
|
||
function getMarketItem(uint256 marketItemId) public view returns (MarketItem memory) { | ||
return idToMarketItem[marketItemId]; | ||
} | ||
|
||
function getListingPrice() public view returns (uint256){ | ||
return listingPrice; | ||
} | ||
|
||
function createMarketItem( | ||
address nftContract, | ||
uint256 tokenId, | ||
uint256 price | ||
) public payable nonReentrant { | ||
require(price > 0, "Price must be at least 1 wei"); | ||
require(msg.value == listingPrice, "Price must be equal to listing price"); | ||
|
||
_itemIds.increment(); | ||
uint256 itemId = _itemIds.current(); | ||
|
||
idToMarketItem[itemId] = MarketItem( | ||
itemId, | ||
nftContract, | ||
tokenId, | ||
payable(msg.sender), | ||
payable(address(0)), | ||
price, | ||
false | ||
); | ||
|
||
IERC721(nftContract).transferFrom(msg.sender, address(this), tokenId); | ||
|
||
emit MarketItemCreated( | ||
itemId, | ||
nftContract, | ||
tokenId, | ||
msg.sender, | ||
address(0), | ||
price, | ||
false | ||
); | ||
} | ||
|
||
function createMarketSale( | ||
address nftContract, | ||
uint256 itemId | ||
) public payable nonReentrant { | ||
uint price = idToMarketItem[itemId].price; | ||
uint tokenId = idToMarketItem[itemId].tokenId; | ||
require(msg.value == price, "Please submit the asking price in order to complete the purchase"); | ||
|
||
idToMarketItem[itemId].seller.transfer(msg.value); | ||
IERC721(nftContract).transferFrom(address(this), msg.sender, tokenId); | ||
idToMarketItem[itemId].owner = payable(msg.sender); | ||
_itemsSold.increment(); | ||
payable(owner).transfer(listingPrice); | ||
} | ||
|
||
//auf dem Markt | ||
function fetchMarketItems() public view returns (MarketItem[] memory) { | ||
uint itemCount = _itemIds.current(); | ||
uint unsoldItemCount = _itemIds.current() - _itemsSold.current(); | ||
uint currentIndex = 0; | ||
|
||
MarketItem[] memory items = new MarketItem[](unsoldItemCount); | ||
for (uint i = 0; i < itemCount; i++) { | ||
if (idToMarketItem[i + 1].owner == address(0)) { | ||
uint currentId = i + 1; | ||
MarketItem storage currentItem = idToMarketItem[currentId]; | ||
items[currentIndex] = currentItem; | ||
currentIndex += 1; | ||
} | ||
} | ||
|
||
return items; | ||
} | ||
|
||
//User purchased | ||
function fetchMyNFTs() public view returns (MarketItem[] memory) { | ||
uint totalItemCount = _itemIds.current(); | ||
uint itemCount = 0; | ||
uint currentIndex = 0; | ||
|
||
for (uint i = 0; i < totalItemCount; i++) { | ||
if (idToMarketItem[i + 1].owner == msg.sender) { | ||
itemCount += 1; | ||
} | ||
} | ||
|
||
MarketItem[] memory items = new MarketItem[](itemCount); | ||
for (uint i = 0; i < totalItemCount; i++) { | ||
if (idToMarketItem[i + 1].owner == msg.sender) { | ||
uint currentId = i + 1; | ||
MarketItem storage currentItem = idToMarketItem[currentId]; | ||
items[currentIndex] = currentItem; | ||
currentIndex += 1; | ||
} | ||
} | ||
|
||
return items; | ||
} | ||
|
||
function redeemNFT(uint256 itemId) public payable nonReentrant { | ||
idToMarketItem[itemId].isRedeemed = true; | ||
} | ||
|
||
// --- | ||
|
||
/* Returns only items a user has listed */ | ||
function fetchItemsListed() public view returns (MarketItem[] memory) { | ||
uint totalItemCount = _itemIds.current(); | ||
uint itemCount = 0; | ||
uint currentIndex = 0; | ||
|
||
for (uint i = 0; i < totalItemCount; i++) { | ||
if (idToMarketItem[i + 1].seller == msg.sender) { | ||
itemCount += 1; | ||
} | ||
} | ||
|
||
MarketItem[] memory items = new MarketItem[](itemCount); | ||
for (uint i = 0; i < totalItemCount; i++) { | ||
if (idToMarketItem[i + 1].seller == msg.sender) { | ||
uint currentId = i + 1; | ||
MarketItem storage currentItem = idToMarketItem[currentId]; | ||
items[currentIndex] = currentItem; | ||
currentIndex += 1; | ||
} | ||
} | ||
return items; | ||
} | ||
} |
Oops, something went wrong.