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

diyici #1

Open
wants to merge 10 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.psd filter=lfs diff=lfs merge=lfs -text
Empty file added README
Empty file.
12 changes: 12 additions & 0 deletions week1-1/Counter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <0.9.0;

contract Counter{
uint256 public counter;
//constructor Counter() {}
function add() public returns(uint256) {
counter = counter + 1;
return counter;
}
}
Binary file added week1-1/Counter代码截图.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1-1/a账户.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1-1/交易哈希.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1-1/转账到位截图.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1-1/转账截图.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1-1/领取以太坊测试币.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added week1-2/hardhat_work1-2.tar.gz
Binary file not shown.
36 changes: 36 additions & 0 deletions week2-1/Bank.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Bank{
//地址到余额的映射
mapping (address=>uint256) private balances;

//存款事件
event Deposit(address indexed account,uint256 amount);

//取钱事件
event Withdrawal(address indexed account,uint256 amount);

//存款函数
function deposit() public payable{
require(msg.value>0,"Deposit amount must be greater than 0.");
balances[msg.sender] += msg.value ;
emit Deposit(msg.sender,msg.value);
}

//取钱函数
function withdraw(uint256 amount)public payable {
require(amount>0,"Withdrawal amount must be greater than 0.");
require(balances[msg.sender]>amount,"Insufficient balance.");
balances[msg.sender]-=amount;
payable(msg.sender).transfer(amount);
emit Withdrawal(msg.sender,amount);
}


//查看余额函数
function getBalances() public view returns(uint256) {
return balances[msg.sender];
}

}
41 changes: 41 additions & 0 deletions week2-2/Score_manage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IScore{
function setScore(address student,uint8 score) external;
}

contract Score is IScore{
//老师地址变量
address public teacher;
//学生地址映射分数
mapping(address=>uint8) scores;
constructor (){
teacher=msg.sender;
}

//仅老师操作
modifier onlyTeacher(){
require(msg.sender == teacher,"only teacher can add or update scores!");
_;
}

//添加学生分数,且不可以大于100
function setScore(address student,uint8 score)public override onlyTeacher {
require(score<=100,"score must be less than or equal 100.");
scores[student]=score;
}
}


contract Teacher{
IScore public scoreContract;
//通过接口调用修改合约分数
constructor (address scoreAddress){
scoreContract =IScore(scoreAddress);
}
function updateScore(address student,uint8 score)public{
scoreContract.setScore(student,score);
}

}
10 changes: 10 additions & 0 deletions week3-1/myerc20/MyERC20 .sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

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

contract MyERC20 is ERC20 {
constructor() ERC20(unicode"YHB_Token", "CAMP2_YHB") {
_mint(msg.sender, 10000 * 10 *18);
}
}
24 changes: 24 additions & 0 deletions week3-1/myerc20/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// You can also run a script with `npx hardhat run <script>`. If you do that, Hardhat
// will compile your contracts, add the Hardhat Runtime Environment's members to the
// global scope, and execute the script.
const { ethers } = require("hardhat");

// const { deploy } = require('@openzeppelin/hardhat-upgrades')

async function main () {
const MyERC20 = await ethers.getContractFactory('MyERC20')
const myERC20 = await MyERC20.deploy();
await myERC20.deployed();

console.log('MyERC20 deployed to:', myERC20.address)
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
22 changes: 22 additions & 0 deletions week3-1/myerc20/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require("@nomicfoundation/hardhat-toolbox");
const Mnemonic = "uncover couple velvet climb predict reject eyebrow border inner fork galaxy soup";

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
networks: {
// goerli: {
// url: "https://eth-goerli.api.onfinality.io/public",
// accounts: [PRIVATE_KEY1,PRIVATE_KEY2],
// chainId: 5,
// },

mumbai: {
url: "https://endpoints.omniatech.io/v1/matic/mumbai/public",
accounts: {
mnemonic: Mnemonic,
},
chainId: 80001,
},
},
solidity: "0.8.18",
};
Binary file added week4-2/4-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.