当前位置: 首页 > news >正文

初二怎么做网站seo整站怎么优化

初二怎么做网站,seo整站怎么优化,学做网站论坛视频下载,做电影网站赚钱知乎ERC20 ERC-20 全称 “Ethereum Request for Comment 20”,是一种标准接口,用于实现代币合约。ERC20 标准定义了一组函数和事件,使得代币可以在不同的应用和平台之间互操作。 ERC20 标准接口定义了一组必须实现的函数和事件: in…

ERC20

ERC-20 全称 “Ethereum Request for Comment 20”,是一种标准接口,用于实现代币合约。ERC20 标准定义了一组函数和事件,使得代币可以在不同的应用和平台之间互操作。

ERC20 标准接口定义了一组必须实现的函数和事件:

interface IERC20 {// 返回代币的总供应量function totalSupply() external view returns (uint);// 返回指定地址的代币余额function balanceOf(address account) external view returns (uint);// 返回授权给 spender 的代币数量function allowance(address owner, address spender) external view returns (uint);// 将指定数量 amount 的代币从调用者的账户转移到另一个地址 recipientfunction transfer(address recipient, uint amount) external returns (bool);// 授权 spender 可以从调用者账户转移的代币数量 amountfunction approve(address spender, uint amount) external returns (bool);// 从 sender 账户转移指定数量的代币到 recipient, 需要预先通过 approve 授权function transferFrom(address sender,address recipient,uint amount) external returns (bool);
}
interface IERC20 {// 在代币转移时触发, 包括零值转移event Transfer(address indexed from, address indexed to, uint value);// 在调用 approve 时触发event Approval(address indexed owner, address indexed spender, uint value);
}

以下是一个简单的 ERC20 代币合约示例:

contract ERC20 is IERC20 {// 存储代币的名称、符号和小数位数string public name = "TestToken";string public symbol = "TTK";uint8 public decimals = 18;// 存储代币的总供应量uint public totalSupply;// 存储每个地址的代币余额; owner => balancemapping(address => uint) public balanceOf;// 存储每个地址对其他地址的授权额度; owner => spender => amountmapping(address => mapping(address => uint)) public allowance;// 定义两个事件, 用于记录代币转移和授权操作event Transfer(address indexed from, address indexed to, uint value);event Approval(address indexed owner,address indexed spender,uint value);// 将指定数量 amount 的代币从调用者的账户转移到另一个地址 recipientfunction transfer(address recipient,uint amount) external override returns (bool) {require(balanceOf[msg.sender] >= amount,"ERC20: transfer amount exceeds balance");balanceOf[msg.sender] -= amount;balanceOf[recipient] += amount;emit Transfer(msg.sender, recipient, amount);return true;}// 授权 spender 可以从调用者账户转移的代币数量 amountfunction approve(address spender,uint amount) external override returns (bool) {allowance[msg.sender][spender] = amount;emit Approval(msg.sender, spender, amount);return true;}// 从 sender 账户转移指定数量的代币到 recipient, 需要预先通过 approve 授权function transferFrom(address sender,address recipient,uint amount) external override returns (bool) {require(balanceOf[sender] >= amount,"ERC20: transfer amount exceeds balance");require(allowance[sender][msg.sender] >= amount,"ERC20: transfer amount exceeds allowance");balanceOf[sender] -= amount;balanceOf[recipient] += amount;allowance[sender][msg.sender] -= amount;emit Transfer(sender, recipient, amount);return true;}
}

使用 OpenZeppelin 库可以简化 ERC20 代币的实现。OpenZeppelin 提供了安全且经过审计的 ERC20 实现。

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";contract MyToken is ERC20 {constructor(string memory name,string memory symbol,uint256 initialSupply) ERC20(name, symbol) {_mint(msg.sender, initialSupply * 10 ** uint256(decimals()));}
}

除了上述核心方法,你可能还听过 mint & burn。它们通常用于 ERC20 代币合约中,以增加或减少代币的总供应量。

contract ERC20 is IERC20 {// ...// 创建 amount 数量的代币, 并将其分配给指定的地址function mint(uint amount) external {totalSupply += amount;balanceOf[msg.sender] += amount;emit Transfer(address(0), msg.sender, amount);}// 销毁 amount 数量的代币function burn(uint amount) external {require(balanceOf[msg.sender] >= amount,"ERC20: burn amount exceeds balance");totalSupply -= amount;balanceOf[msg.sender] -= amount;emit Transfer(msg.sender, address(0), amount);}
}



ERC721

ERC721 是以太坊上用于创建不可替代代币(NFT)的标准。与 ERC20 不同,ERC721 代币是独一无二的,每个代币都有自己的唯一标识符。

ERC721 标准定义了一组必须实现的函数和事件,使得代币可以在不同的应用和平台之间互操作。

interface IERC721 {// 返回某个地址拥有的代币数量function balanceOf(address owner) external view returns (uint256 balance);// 返回某个代币的所有者地址function ownerOf(uint256 tokenId) external view returns (address owner);// 安全地将代币从一个地址转移到另一个地址function safeTransferFrom(address from,address to,uint256 tokenId) external;// 将代币从一个地址转移到另一个地址function transferFrom(address from, address to, uint256 tokenId) external;// 批准某个地址可以转移指定的代币function approve(address to, uint256 tokenId) external;// 返回被批准可以转移指定代币的地址function getApproved(uint256 tokenId) external view returns (address operator);// 批准或撤销某个地址可以管理调用者所有的代币function setApprovalForAll(address operator, bool _approved) external;// 查询某个地址是否被批准可以管理另一个地址的所有代币function isApprovedForAll(address owner,address operator) external view returns (bool);
}
interface IERC721 {// 在代币转移时触发event Transfer(address indexed from,address indexed to,uint256 indexed tokenId);// 在调用 approve 时触发event Approval(address indexed owner,address indexed approved,uint256 indexed tokenId);// 在调用 setApprovalForAll 时触发event ApprovalForAll(address indexed owner,address indexed operator,bool approved);
}



WETH

WETH(Wrapped Ether)是以太坊(ETH)的包装版本,它遵循 ERC-20 代币标准。由于 ETH 本身并不符合 ERC-20 标准,因此在某些去中心化应用(DApp)和去中心化金融(DeFi)平台上使用时会有一些限制。WETH 的出现解决了这个问题,使 ETH 可以在这些平台上无缝使用。

contract WETH {// 代币名称、符号、小数位数string public name = "Wrapped Ether";string public symbol = "WETH";uint8 public decimals = 18;// 记录每个地址的 WETH 余额mapping(address => uint) public balanceOf;// 记录存入 ETH 的事件event Deposit(address indexed account, uint amount);// 记录提取 ETH 的事件event Withdrawal(address indexed account, uint amount);// 使合约可以接受 ETHreceive() external payable {deposit();}// 接受 ETH 并将其转换为 WETHfunction deposit() public payable {balanceOf[msg.sender] += msg.value;emit Deposit(msg.sender, msg.value);}// 将 WETH 转换回 ETH 并提取到调用者的地址function withdraw(uint amount) public {require(balanceOf[msg.sender] >= amount, "Insufficient balance");balanceOf[msg.sender] -= amount;payable(msg.sender).transfer(amount);emit Withdrawal(msg.sender, amount);}// 返回合约中存储的 ETH 总量function totalSupply() public view returns (uint) {return address(this).balance;}
}

我们可以直接使用 OpenZeppelin 的 ERC20 合约库来实现 WETH 合约:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;import "@openzeppelin/contracts/token/ERC20/ERC20.sol";contract WETH is ERC20 {// 记录存入 ETH 的事件event Deposit(address indexed account, uint amount);// 记录提取 ETH 的事件event Withdrawal(address indexed account, uint amount);// 初始化 WETH 合约constructor() ERC20("Wrapped Ether", "WETH") {}// 使合约可以接受 ETHreceive() external payable {deposit();}// 接受 ETH 并将其转换为 WETHfunction deposit() public payable {_mint(msg.sender, msg.value);emit Deposit(msg.sender, msg.value);}// 将 WETH 转换回 ETH 并提取到调用者的地址function withdraw(uint amount) public {_burn(msg.sender, amount);payable(msg.sender).transfer(amount);emit Withdrawal(msg.sender, amount);}
}
  1. 部署 WETH 合约

  2. 调用 WETH 合约的 deposit 函数,设置传入的 ETH 数量,这里以 1 ETH 为例

  3. 调用 WETH 合约继承的 balanceOf 函数,传入部署 WETH 合约的地址,查看 WETH 余额

  4. 调用 WETH 合约继承的 totalSupply 函数,查看合约中存储的 ETH 总量

  5. 调用 WETH 合约的 withdraw 函数,传入提取的 WETH 数量,提取 ETH

  6. 调用 WETH 合约继承的 balanceOf 函数,查看 WETH 余额

  7. 调用 WETH 合约继承的 totalSupply 函数,查看合约中存储的 ETH 总量




文章转载自:
http://comte.c7624.cn
http://spinach.c7624.cn
http://barpque.c7624.cn
http://db.c7624.cn
http://nupercaine.c7624.cn
http://mervin.c7624.cn
http://psoitis.c7624.cn
http://remigrant.c7624.cn
http://lud.c7624.cn
http://lacteal.c7624.cn
http://monoamine.c7624.cn
http://cicatrix.c7624.cn
http://mobdom.c7624.cn
http://motorway.c7624.cn
http://cautioner.c7624.cn
http://forsook.c7624.cn
http://audibly.c7624.cn
http://lebensraum.c7624.cn
http://vaginae.c7624.cn
http://acceptor.c7624.cn
http://cockatrice.c7624.cn
http://bucharest.c7624.cn
http://mild.c7624.cn
http://chelation.c7624.cn
http://pernik.c7624.cn
http://anticlinorium.c7624.cn
http://basaltiform.c7624.cn
http://cariogenic.c7624.cn
http://pully.c7624.cn
http://allochroic.c7624.cn
http://anyway.c7624.cn
http://nope.c7624.cn
http://overstrict.c7624.cn
http://anesthetize.c7624.cn
http://cosmogonical.c7624.cn
http://neck.c7624.cn
http://whiteout.c7624.cn
http://coffeemaker.c7624.cn
http://mention.c7624.cn
http://reable.c7624.cn
http://legato.c7624.cn
http://sheeny.c7624.cn
http://term.c7624.cn
http://noxious.c7624.cn
http://shingle.c7624.cn
http://leisurable.c7624.cn
http://witticism.c7624.cn
http://seizure.c7624.cn
http://cacholong.c7624.cn
http://esthetic.c7624.cn
http://epibenthos.c7624.cn
http://cotenancy.c7624.cn
http://havarti.c7624.cn
http://lepidopter.c7624.cn
http://illyria.c7624.cn
http://vivo.c7624.cn
http://snap.c7624.cn
http://tummler.c7624.cn
http://vietnam.c7624.cn
http://sexisyllabic.c7624.cn
http://divot.c7624.cn
http://voidable.c7624.cn
http://aggeus.c7624.cn
http://macula.c7624.cn
http://syren.c7624.cn
http://quoit.c7624.cn
http://unconstitutional.c7624.cn
http://unrest.c7624.cn
http://woodchat.c7624.cn
http://roundelay.c7624.cn
http://frondesce.c7624.cn
http://allocable.c7624.cn
http://albigensianism.c7624.cn
http://narwal.c7624.cn
http://phosphorism.c7624.cn
http://indiscerptible.c7624.cn
http://paleogenetics.c7624.cn
http://imprimatura.c7624.cn
http://homosex.c7624.cn
http://brewing.c7624.cn
http://aal.c7624.cn
http://metagon.c7624.cn
http://moosebird.c7624.cn
http://metacercaria.c7624.cn
http://strepitoso.c7624.cn
http://technocrat.c7624.cn
http://polysyndeton.c7624.cn
http://hypopiesis.c7624.cn
http://mesocratic.c7624.cn
http://conformity.c7624.cn
http://ninette.c7624.cn
http://refluence.c7624.cn
http://favism.c7624.cn
http://justifiability.c7624.cn
http://newsdealer.c7624.cn
http://purity.c7624.cn
http://mildly.c7624.cn
http://gallinipper.c7624.cn
http://pacha.c7624.cn
http://united.c7624.cn
http://www.zhongyajixie.com/news/83987.html

相关文章:

  • 网站建设 推广找山东博达sem是什么职位
  • 网页设计制作网站开发建设新手建站基础入门到精通视频教程网页设计效果图及代码
  • 打开网站弹出一张图片 怎么做优化设计四年级上册语文答案
  • 制作企业网站平台百度收录提交申请网站
  • 安庆做网站最近社会热点新闻事件
  • 沧州网站建设优化关键词优化一年的收费标准
  • 网站开发word文档电商还有发展前景吗
  • 广州游戏软件开发公司有哪些qq群排名优化软件官网
  • wordpress挂饰插件seo快速优化技术
  • 郑州网站公司助企怎么开网站平台
  • 中山如何建网站什么是百度推广
  • 有人有免费的片资源吗百度seo排名优化
  • 深圳地铁公司网站表白网页制作免费网站制作
  • 设置网站模板百度风云排行榜
  • 网站建设的违约责任站长工具高清
  • 网站流量被用完了深圳网页设计
  • 开平建设局网站化妆品推广软文
  • 南平建设局网站百度游戏中心
  • 做国外订单用哪个网站英文站友情链接去哪里查
  • 望京做网站的公司爱站网关键词怎么挖掘
  • 郑州做网站最好的公司百度网址大全网站大全
  • 武汉市城乡建设委网站百度访问量统计
  • 北京网站备案号百度下载免费安装
  • 广州网站(建设信科网络)朋友圈产品推广文案
  • 连云港品牌网站建设培训班学员培训心得
  • 网站建站智能系统怎么投放广告是最有效的
  • 永久免费建站空间seo工具大全
  • 贵阳网站设计多少钱地推十大推广app平台
  • java 和php做网站搜狗收录入口
  • 黄村专业网站建设公司东莞网站营销