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

task3: missop #1413

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions members/missop/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Web3 前端训练营报名

## 个人信息

* GitHub ID:missop
* OpenBuild Username:4W3QwS3M
* ERC20 钱包地址: (首次如果没有,学习完毕钱包在填写)0x940dB67293C56cFAd8a1D3eC297A2cC1A4b10e4B

### 个人介绍
Binary file added members/missop/task2/bind-wallet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions members/missop/task2/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Task2 Blockchain Basic

本任务分为简答题、分析题和选择题,以此为模板,在下方填写你的答案即可。

选择题,请在你选中的项目中,将 `[ ]` 改为 `[x]` 即可

## [单选题] 如果你莫名奇妙收到了一个 NFT,那么

- [ ] 天上掉米,我应该马上点开他的链接
- [ x ] 这可能是在对我进行诈骗!

## [单选题] 群里大哥给我发的网站,说能赚大米,我应该

- [ ] 赶紧冲啊,待会米被人抢了
- [ x ] 谨慎判断,不在不信任的网站链接钱包

## [单选题] 下列说法正确的是

- [ ] 一个私钥对应一个地址
- [ x ] 一个私钥对应多个地址
- [ ] 多个私钥对应一个地址
- [ ] 多个私钥对应多个地址

## [单选题] 下列哪个是以太坊虚拟机的简称

- [ ] CLR
- [ x ] EVM
- [ ] JVM

## [单选题] 以下哪个是以太坊上正确的地址格式?

- [ ] 1A4BHoT2sXFuHsyL6bnTcD1m6AP9C5uyT1
- [ ] TEEuMMSc6zPJD36gfjBAR2GmqT6Tu1Rcut
- [ ] 0x997fd71a4cf5d214009619808176b947aec122890a7fcee02e78e329596c94ba
- [ x ] 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

## [多选题] 有一天某个大哥说要按市场价的 80% 出油给你,有可能

- [ x ] 他在洗米
- [ ] 他良心发现
- [ x ] 要给我黒米
- [ x ] 给我下套呢

## [多选题] 以下哪些是以太坊的二层扩容方案?

- [ ] Lightning Network(闪电网络)
- [ ] Optimsitic Rollup
- [ x ] Zk Rollup

## [简答题] 简述区块链的网络结构

```
区块链系统自下而上可分为六层结构:数据层、网络层、共识层、激励层、合约层和应用层。其中,数据层、网络层、共识层是区块链的必要元素,激励层、合约层、应用层不是区块链的必要元素。

数据层:作为最底层封装了数据区块以及相关数据加密和时间戳等技术。
网络层:包括分布式组网机制、数据传播机制和数据验证机制等。
共识层:主要封装网络节点的各类共识算法。
激励层:它将经济因素集成到区块链技术体系,包括经济激励的发行机制和分配机制,主要出现在公链中。
合约层:它封装各种脚本、算法和智能合约。
应用层:封装了区块链的各种应用场景和案例。
```

## [简答题] 智能合约是什么,有何作用?

```
智能合约是一种计算机程序,它存储并运行在一个去中心化的“无需信任”的网络上,比如区块链。
```

## [简答题] 怎么理解大家常说的 `EVM` 这个词汇?

```
以太坊虚拟机 (EVM) 是一个去中心化虚拟环境,它在所有以太坊节点上一种安全一致地方式执行代码。 节点运行以太坊虚拟机,以执行智能合约,利用“燃料”度量执行操作所需的计算工作,从而确保高效的资源分配和网络安全性。
```

## [分析题] 你对去中心化的理解

```
去中心就是每个人都是中心,而不是把数据掌握在一个人活着少数人手里
```

## [分析题] 比较区块链与传统数据库,你的看法?

```
传统数据库是中心化的,而区块链是中心化的;传统数据库是可信任的,而区块链是不可信任的;传统数据库是可篡改的,而区块链是不可篡改的;传统数据库是可伪造的,而区块链是不可伪造的。
```

## 操作题

安装一个 WEB3 钱包,创建账户后与 [openbuild.xyz](https://openbuild.xyz/profile) 进行绑定,截图后文件命名为 `./bind-wallet.jpg`.
15 changes: 15 additions & 0 deletions members/missop/task3/MissopToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MissopToken is ERC20{
constructor() ERC20("MissopToken","MT") {
// 初始化给合约 mint 这么多 token
_mint(msg.sender, 10000000000*10**6);
}

function decimals()public view virtual override returns (uint8) {
return 6;
}
}
83 changes: 83 additions & 0 deletions members/missop/task3/NftMarket.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; // 防止双花攻击

error NftMarket__NotOwnerOf(string message);
error NftMarket__NotApproved(string message);
error NftMarket__NotActive(string message);
error NftMarket__PaymentFailed(string message);

contract NftMarket is ReentrancyGuard {
struct Listing{
address seller;
address nftContract;
uint256 tokenId;
uint256 price;
bool isActive;
}

mapping(address => mapping (uint256 => Listing)) s_listings;
IERC20 public immutable i_paymentToken;

// 上架 nft 事件
event NftListed(
address indexed seller,
uint256 indexed tokenId,
address indexed nftContract,
uint256 price
);

// nft购买事件
event NftPurchased(
address indexed buyer,
uint256 indexed tokenId,
address indexed nftContract,
uint256 price
);

constructor(address _paymentToken) {
i_paymentToken = IERC20(_paymentToken);
}

function listNft(address _nftContract,uint256 tokenId,uint256 price) external {
IERC721 nft = IERC721(_nftContract);
if(nft.ownerOf(tokenId) != msg.sender){
revert NftMarket__NotOwnerOf("not the owner of the NFT");
}
if(!nft.isApprovedForAll(msg.sender, address(this))){
revert NftMarket__NotApproved("not approved");
}
s_listings[_nftContract][tokenId] = Listing(
msg.sender,
_nftContract,
tokenId,
price,
true
);

emit NftListed(
msg.sender,
tokenId,
_nftContract,
price
);
}

function buyNft(address _nftContract,uint256 _tokenId) external {
Listing storage listing = s_listings[_nftContract][_tokenId];
if(!listing.isActive){
revert NftMarket__NotActive("NFT not active");
}
IERC721 nft = IERC721(_nftContract);
// 将购买人身上的钱转给售卖人
if(!i_paymentToken.transferFrom(msg.sender, listing.seller, listing.price)){
revert NftMarket__PaymentFailed("payment failed");
}
nft.safeTransferFrom(listing.seller, msg.sender, _tokenId);
listing.isActive = false;
emit NftPurchased(msg.sender, _tokenId, _nftContract, listing.price);
}
}
21 changes: 21 additions & 0 deletions members/missop/task3/NftToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract NftToken is ERC721 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;

// 每 mint 一个 nft 都需要把 count+1 表示 nft 总数量
constructor() ERC721("NftToken","NT") {
_tokenIdCounter.increment();
}

function mint(address to) public {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}
}
6 changes: 6 additions & 0 deletions members/missop/task3/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 作业
由于Sepolia燃气费用太高,部署到了Avalanche Fuji

上架:0x9a1741e45f8d38e420af23e6b585233fd02fe011ee6524125b3d78a5bfaa8aaa

购买:0xb03a45c0f0fa911b1017a9b9176aab906746588f37b5dcce166f26761829ba26