Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #1

Merged
merged 43 commits into from
Nov 29, 2021
Merged

V2 #1

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1582ae2
clean pages
askender Oct 21, 2021
d6bbaeb
add article and show
askender Oct 21, 2021
90be3e4
add markdown render
askender Oct 21, 2021
8935f81
add markdown render
askender Oct 21, 2021
bd6f62b
add markdown render
askender Oct 21, 2021
ab769a5
add markdown render
askender Oct 21, 2021
b242209
add markdown render
askender Oct 21, 2021
2d6433d
add markdown render
askender Oct 21, 2021
74725ad
fix build
askender Oct 21, 2021
81a1b3f
fix build
askender Oct 21, 2021
5cb10df
fix build
askender Oct 21, 2021
899d69e
fix article page
askender Oct 27, 2021
0061b68
fix article page 2
askender Oct 27, 2021
e7ed7aa
fix article page 2
askender Oct 27, 2021
bab99cf
fix article page 3
askender Oct 27, 2021
4e2e00c
fix article page 4
askender Oct 28, 2021
9765466
fix article page 5
askender Oct 28, 2021
21b056b
fix article page 6
askender Oct 28, 2021
97c33fc
fix article page 6
askender Oct 28, 2021
dfea3c1
fix article page 6
askender Oct 28, 2021
7eddfa5
fix article page 7
askender Oct 28, 2021
508f801
new contracts
askender Oct 28, 2021
51e0913
fix ux
askender Oct 28, 2021
f7a0939
fix contracts
askender Oct 30, 2021
3cecb58
add storage of fil-polygon-bridge
askender Nov 12, 2021
9be305a
add doc and fix localstorage
askender Nov 14, 2021
96d8c80
fix login
askender Nov 14, 2021
4c7a24d
fix login
askender Nov 14, 2021
84bb18e
fix login
askender Nov 14, 2021
09e7f21
fix render
askender Nov 14, 2021
b7ebc15
fix render
askender Nov 14, 2021
afdfc87
fix render
askender Nov 14, 2021
bef2cf9
fix render
askender Nov 14, 2021
e7ab25e
fix ux
askender Nov 14, 2021
2b67d1d
fix ux
askender Nov 14, 2021
583f0b0
fix ux
askender Nov 14, 2021
3f0d98e
add change-tab css style
askender Nov 16, 2021
637f9a4
add change-tab css style, fix
askender Nov 16, 2021
a3458a3
fix contracts
askender Nov 16, 2021
f498d1c
fix which/that
askender Nov 16, 2021
aeeddf3
raw readme
askender Nov 29, 2021
9664d6e
new readme
askender Nov 29, 2021
7f79e22
use webpack5
askender Nov 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ node_modules
cache
artifacts

*_raw
# contract type generation
/contracts/types

*_raw
133 changes: 39 additions & 94 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,109 +1,54 @@
## Full stack NFT marketplace built with Polygon, Solidity, IPFS, & Next.js
# Creative Comomons NFT Playground

![Header](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pfofv47dooojerkmfgr4.png)
## 📢Tips
- 🌏 Every NFT here is licensed under Creative Commons Attribution 4.0 International License. 🅭
- 🎁 Buying NFT is to donate tokens to the NFT minter(maybe the author). You can't sell it to others.
- 🎓 Please don’t mint anything that doesn’t belong to you. We have a Dweb DAO to help check cheating behavious. (Welcome to join the DAO.)

### Running this project
## 📢注意
- 🌏 这里的所有NFT作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。 🅭
- 🎁 购买NFT仅仅意味着你向NFT铸造者(可能是作品作者)捐款。你不能将该NFT卖给其他人。
- 🎓 请不要将任何不属于你的作品铸造为NFT。 我们有一个Dweb DAO帮助检测欺骗行为。(也欢迎加入)

#### Gitpod

To deploy this project to Gitpod, follow these steps:
## The Features
- 🌏 All Creative Commons licensed articles will be stored on IPFS and indexed in dweb search engines(such as Dweb Search).
- 🎁 Authers can mint the articles as NFTs and push them to market with very low gas fee(with Polygon network). Users can buy NFTs (articles) which they like, just for donation.
- 🎓 The NFTs will be stored both on IPFS and Filecoin with nft.storage and Filecoin-Polygon-Bridge so we can help store valuable data on web permanently.

1. Click this link to deploy

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#github.com/dabit3/polygon-ethereum-nextjs-marketplace)
## (O_O)? Question?
- 🔗 We use mumbai test network. You can add it to your Metamask with Chainlist
- 🌏 You can join Dweb Lab Discord
- 🌃 There is also an IPFS version: ipfs://QmSp1Y8TJLQ2dJyYd5uZS7iqGDLPChf2rSsK1R8KkTgY2i

2. In __pages/index.js__, pass in the RPC address given to you by GitPod to the call to `JsonRpcProvider` function:

```javascript
/* update this: */
const provider = new ethers.providers.JsonRpcProvider()
## License
https://opensource.org/licenses/MIT

/* to this: */
const provider = new ethers.providers.JsonRpcProvider("https://8545-youendpoint.gitpod.io/")
```

3. Import the RPC address given to you by GitPod into your MetaMask wallet
## Design
## 设计
- 1 人类:理想情况下,高质量知识应该免费公开传播
- 2 作者:作者需要生存
- 3 读者:读者面对众多作品,注意力有限,难以高效分辨作品质量是否符合自己的需求
- 4 市场:如果一个作品能被多次交易,容易让人陷入炒作而非关注作品本身;但部分读者有实力支持作者
- 为了让以上4者更好的共存,提供一个作品发布工具,作品均以CC-BY-SA分享(满足1),无付费墙和传播墙;可选制作为NFT,购买NFT的主要作用是捐赠作者,即使不购买NFT也可以直接给作者捐赠(满足2); 捐赠也帮助增加作品的影响力,用于3次方投票;读者可自由参考3次方投票辅助选择作品,多了一个选择的维度(满足3);单个作品只能被购买一次(满足4)

![MetaMask RPC Import](wallet.png)
## 博弈分析
- 问题1 作者会考虑自己开多个账号自己买自己的作品来增加影响力。每个策展平台自由选择影响因子算法;而3次方投票仅为其中一个影响因子
- 问题2 作品均可以免费查看,无需NFT,只需给作者捐赠就好。是的,这只是一个用于支持Creative Comomons内容的NFT实验,nft-for-fun
- 问题3 作者可能会重复发自己的作品赚取费用,由于信息公开可查,检测应该不难
- 问题4 NFT流动性差。我们不在乎NFT的流动性

#### Local setup

To run this project locally, follow these steps.
## 名词解释
- CC-BY-SA 知识共享-署名-相同方式共享 (属于自由文化许可协议)
- DwebVerse Marketplace

1. Clone the project locally, change into the directory, and install the dependencies:

```sh
git clone https://github.com/dabit3/polygon-ethereum-nextjs-marketplace.git

cd polygon-ethereum-nextjs-marketplace

# install using NPM or Yarn
npm install

# or

yarn
```

2. Start the local Hardhat node

```sh
npx hardhat node
```

3. With the network running, deploy the contracts to the local network in a separate terminal window

```sh
npx hardhat run scripts/deploy.js --network localhost
```

4. Start the app

```
npm run dev
```

### Configuration

To deploy to Polygon test or main networks, update the configurations located in __hardhat.config.js__ to use a private key and, optionally, deploy to a private RPC like Infura.

```javascript
require("@nomiclabs/hardhat-waffle");
const fs = require('fs');
const privateKey = fs.readFileSync(".secret").toString().trim() || "01234567890123456789";

// infuraId is optional if you are using Infura RPC
const infuraId = fs.readFileSync(".infuraid").toString().trim() || "";

module.exports = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 1337
},
mumbai: {
// Infura
// url: `https://polygon-mumbai.infura.io/v3/${infuraId}`
url: "https://rpc-mumbai.matic.today",
accounts: [privateKey]
},
matic: {
// Infura
// url: `https://polygon-mainnet.infura.io/v3/${infuraId}`,
url: "https://rpc-mainnet.maticvigil.com",
accounts: [privateKey]
}
},
solidity: {
version: "0.8.4",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
}
};
```

If using Infura, update __.infuraid__ with your [Infura](https://infura.io/) project ID.
## 使用方法
- step1: 发布metadata信息,信息存在dweb search engine等开放接口的引擎里。信息公开
- step2: mint 只需要支付不到1分钱的gas费用,但作品没有被发到NFT market
- step3: 将NFT发到市场上,可在市场公开查看,需要支付不到1分钱的gas费
- step4: 买家买走
109 changes: 109 additions & 0 deletions README_raw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
## Full stack NFT marketplace built with Polygon, Solidity, IPFS, & Next.js

![Header](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pfofv47dooojerkmfgr4.png)

### Running this project

#### Gitpod

To deploy this project to Gitpod, follow these steps:

1. Click this link to deploy

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#github.com/dabit3/polygon-ethereum-nextjs-marketplace)

2. In __pages/index.js__, pass in the RPC address given to you by GitPod to the call to `JsonRpcProvider` function:

```javascript
/* update this: */
const provider = new ethers.providers.JsonRpcProvider()

/* to this: */
const provider = new ethers.providers.JsonRpcProvider("https://8545-youendpoint.gitpod.io/")
```

3. Import the RPC address given to you by GitPod into your MetaMask wallet

![MetaMask RPC Import](wallet.png)

#### Local setup

To run this project locally, follow these steps.

1. Clone the project locally, change into the directory, and install the dependencies:

```sh
git clone https://github.com/dabit3/polygon-ethereum-nextjs-marketplace.git

cd polygon-ethereum-nextjs-marketplace

# install using NPM or Yarn
npm install

# or

yarn
```

2. Start the local Hardhat node

```sh
npx hardhat node
```

3. With the network running, deploy the contracts to the local network in a separate terminal window

```sh
npx hardhat run scripts/deploy.js --network localhost
```

4. Start the app

```
npm run dev
```

### Configuration

To deploy to Polygon test or main networks, update the configurations located in __hardhat.config.js__ to use a private key and, optionally, deploy to a private RPC like Infura.

```javascript
require("@nomiclabs/hardhat-waffle");
const fs = require('fs');
const privateKey = fs.readFileSync(".secret").toString().trim() || "01234567890123456789";

// infuraId is optional if you are using Infura RPC
const infuraId = fs.readFileSync(".infuraid").toString().trim() || "";

module.exports = {
defaultNetwork: "hardhat",
networks: {
hardhat: {
chainId: 1337
},
mumbai: {
// Infura
// url: `https://polygon-mumbai.infura.io/v3/${infuraId}`
url: "https://rpc-mumbai.matic.today",
accounts: [privateKey]
},
matic: {
// Infura
// url: `https://polygon-mainnet.infura.io/v3/${infuraId}`,
url: "https://rpc-mainnet.maticvigil.com",
accounts: [privateKey]
}
},
solidity: {
version: "0.8.4",
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
}
};
```

If using Infura, update __.infuraid__ with your [Infura](https://infura.io/) project ID.
34 changes: 26 additions & 8 deletions contracts/Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ pragma solidity ^0.8.3;
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

import "hardhat/console.sol";

contract NFTMarket is ReentrancyGuard {
using Counters for Counters.Counter;
Counters.Counter private _itemIds;
Counters.Counter private _itemsSold;

address payable owner;
// uint256 listingPrice = 0.025 ether;
uint256 listingPrice = 0.001 ether;
uint256 listingPrice = 0.0001 ether;

constructor() {
owner = payable(msg.sender);
Expand All @@ -31,6 +28,7 @@ contract NFTMarket is ReentrancyGuard {
}

mapping(uint256 => MarketItem) private idToMarketItem;
mapping(uint256 => MarketItem) private tidToMarketItem;

event MarketItemCreated (
uint indexed itemId,
Expand All @@ -56,9 +54,9 @@ contract NFTMarket is ReentrancyGuard {
require(price > 0, "Price must be at least 1 wei");
require(msg.value == listingPrice, "Price must be equal to listing price");

_itemIds.increment();
_itemIds.increment(); // should not use itemid
uint256 itemId = _itemIds.current();

idToMarketItem[itemId] = MarketItem(
itemId,
nftContract,
Expand All @@ -68,6 +66,16 @@ contract NFTMarket is ReentrancyGuard {
price,
false
);
// fix bug, use tokenId, needed when sale
tidToMarketItem[tokenId] = MarketItem(
itemId,
nftContract,
tokenId,
payable(msg.sender),
payable(address(0)),
price,
false
);

IERC721(nftContract).transferFrom(msg.sender, address(this), tokenId);

Expand All @@ -88,14 +96,22 @@ contract NFTMarket is ReentrancyGuard {
address nftContract,
uint256 itemId
) public payable nonReentrant {
uint price = idToMarketItem[itemId].price;
uint tokenId = idToMarketItem[itemId].tokenId;
// Note: idToMarketItem maybe less than allItem(some item-minted-not-goto-market)
// so price = allItem[itemId].price
// so tokenId = allItem[itemId].tokenId // tokenId === itemId

// uint tokenId = idToMarketItem[itemId].tokenId;
// get price by itemid
uint tokenId = itemId;
uint price = tidToMarketItem[itemId].price;

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);
idToMarketItem[itemId].sold = true;
// tidToMarketItem
_itemsSold.increment();
payable(owner).transfer(listingPrice);
}
Expand All @@ -115,9 +131,11 @@ contract NFTMarket is ReentrancyGuard {
currentIndex += 1;
}
}

return items;
}


/* Returns only items that a user has purchased */
function fetchMyNFTs() public view returns (MarketItem[] memory) {
uint totalItemCount = _itemIds.current();
Expand Down
Loading