Solidity 与链上开发学习笔记(6-7 月)
这些是学习过程中随手记的片段,原本分散在多个按日期命名的文件里。内容本身很零碎—— 有工具链接、有当时没想明白的概念、也有一句话的结论。合并到一处按时间排列,是为了能 回头看清楚学习路径,而不是把它们当成成文的教程。
2026-06-17
测试钱包地址 https://metamask.io/zh-CN
水龙头 https://sepolia.etherscan.io/ https://faucetpay.io/
查看钱包及交易记录 https://etherscan.io/
区块链直观演示说明网站 https://andersbrownworth.com/blockchain/
交易加密及key https://andersbrownworth.com/blockchain/public-private-keys/keys
2026-06-22
pure view是两个专门用于读取变量的函数,区别在于view可以读取环境变量或赋值数值的当前值,pure只能直接返回值;
关于调用和读取花费gas的规则和情况,默认直接调用pure/view类型函数式无需耗费gas的,但是如果是合约中函数里有调用此二者类型的过程则会少量增加gas消耗,因为本质上是在实际合约函数执行中增加了工作量
returns规定了函数返回什么类型的数据及结果
错误和警告的显示、查看、处理、影响
Stack \memory\storage\calldata\code\logs
结构体、字符串需要声明为memory,字符串本身是bytes array,二uint256这样的类型无需单独指定是因为solidity本身知道应该将其如何存放;
默认函数外的合约内变量都是storage;函数参数中的只涉及memory以及calldata,但后者是不可变值类型,因此采用memory
sepolia的水龙头上获取初始测试币,然后真实连接并测试部署
2026-07-08
不同的文件中的合约内容可以全量复制粘贴在调用处,但是这非常不合理也不方便,所以采用import进行对应的文件及模块引入,引入原则就是文件对应的文件目录位置,通过./xxx.sol进行引入和使用;
单纯的import是全量引入,一般可以按需引入,如 import {xxStorage,xyStorage} from ""./xx.sol"
引入之后的合约变量定义及赋值和使用有点像类和对象的概念such as:
SampleStorage public anyNameStorage;
2026-07-09
继承关系is的处理和使用
继承意味着拥有同等的权限和功能及访问等,包括函数调用、数据变量等
Virtual/override
Summary:
new keyword
Address\ABI
is
Virtual overeride
2026-07-10
transaction fields:
Nonce:tx count for the account
Gas Price: price per unit of gas (in wei)
Gas Limit: max gas that this tx can use
To: address that the tx is sent to
Value: amount of wei to send
Data: what to send to the To address
v,r,s: components of txsignature
revert
chainlink
Chainlink VRF
chainlink Keepers
function getPrice() public view returns(uint256){
AggregatorV3Interfaver priceFeed = AggregatorV3Interfaver(xxx);
(,int256 price,,,) = priceFeed.latestRoundData();
return uint256(price*1e10);
}
Cofrin 教程网站 https://solidity-by-example.org/hello-world/
Library
safeMoth uncheck
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {PriceConverter} from "./PriceConverter.sol";
contract FundMe {
using PriceConverter for uint256;
uint256 public minimumUsd = 5e18;
address[] public funders;
mapping(address funder => uint256 amountFunded) public addressToAmountFunded;
function fund() public payable {
require(msg.value.getConversionRate() >= minimumUsd, "didn't send enough ETH");
funders.push(msg.sender);
addressToAmountFunded [msg. sender] = addressToAmountFunded Imsg. sender] + msg.value;
}
}
For loop
transfer send call
Receive fallback
github question
2026-07-16
book.getfoundry.sh
forge
anvil
ganache
Trufflesuite.com
Go-ethereum
ganache和anvil方式的合约部署到区块链上
命令行方式直接interactive方式进行交互式写入及部署
script脚本进行部署
.s.sol是foundry文件格式结尾后缀
.env等方式存储private-key是不安全的,更别说shell中的直接明文--private-key或者 --rpc-url
Thirdweb.com
cast --to-base
cast send
cast call
Alchemy.com
sepolia
文件验证合约
forge fmt
forge install
forge test
2026-07-23
策略模式配置NetworkConfig从而进行适配和灵活兼容及调整
magicNumber
replace magicNumber to readable code like constant
using good understand name to handle function or any process include variables
Repeat is the mother of skill