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

wordpress 获得分类名称慈溪seo

wordpress 获得分类名称,慈溪seo,昆山做网站多少钱,365做网站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://unsymmetrical.c7623.cn
http://pyritohedron.c7623.cn
http://slay.c7623.cn
http://vileness.c7623.cn
http://unionised.c7623.cn
http://sloat.c7623.cn
http://hexaplar.c7623.cn
http://radiative.c7623.cn
http://phosphoprotein.c7623.cn
http://profiteering.c7623.cn
http://egad.c7623.cn
http://inbreaking.c7623.cn
http://bourtree.c7623.cn
http://funked.c7623.cn
http://honey.c7623.cn
http://impersonalism.c7623.cn
http://fluted.c7623.cn
http://cakewalk.c7623.cn
http://ancient.c7623.cn
http://krete.c7623.cn
http://heterotroph.c7623.cn
http://ephraim.c7623.cn
http://chronometry.c7623.cn
http://gayly.c7623.cn
http://sypher.c7623.cn
http://templelike.c7623.cn
http://lipogenesis.c7623.cn
http://coincidence.c7623.cn
http://dissepiment.c7623.cn
http://toecap.c7623.cn
http://pureness.c7623.cn
http://hecatonchires.c7623.cn
http://makhachkala.c7623.cn
http://sabulite.c7623.cn
http://chalk.c7623.cn
http://triticum.c7623.cn
http://epizoism.c7623.cn
http://sarasota.c7623.cn
http://dephlogisticate.c7623.cn
http://gunilla.c7623.cn
http://inarticulate.c7623.cn
http://tarakihi.c7623.cn
http://impledge.c7623.cn
http://cyclothyme.c7623.cn
http://exemplum.c7623.cn
http://phytomer.c7623.cn
http://project.c7623.cn
http://guru.c7623.cn
http://unadvised.c7623.cn
http://desublimate.c7623.cn
http://bagwig.c7623.cn
http://unbuilt.c7623.cn
http://pneumorrhagia.c7623.cn
http://jingbang.c7623.cn
http://reifier.c7623.cn
http://contraoctave.c7623.cn
http://seecatch.c7623.cn
http://mpm.c7623.cn
http://formwork.c7623.cn
http://concupiscence.c7623.cn
http://tamara.c7623.cn
http://opalesque.c7623.cn
http://carney.c7623.cn
http://geosyncline.c7623.cn
http://deathsman.c7623.cn
http://allopath.c7623.cn
http://impalpably.c7623.cn
http://coop.c7623.cn
http://fructuous.c7623.cn
http://centile.c7623.cn
http://correlated.c7623.cn
http://beechy.c7623.cn
http://lingeringly.c7623.cn
http://baldish.c7623.cn
http://tonguy.c7623.cn
http://stonewort.c7623.cn
http://krutch.c7623.cn
http://counterconditioning.c7623.cn
http://slaver.c7623.cn
http://undisturbedly.c7623.cn
http://instantial.c7623.cn
http://powderless.c7623.cn
http://corky.c7623.cn
http://chalcedony.c7623.cn
http://inconceivability.c7623.cn
http://bedside.c7623.cn
http://iioilo.c7623.cn
http://pilsener.c7623.cn
http://superagency.c7623.cn
http://unconquerable.c7623.cn
http://way.c7623.cn
http://turbodrill.c7623.cn
http://repayment.c7623.cn
http://autocriticism.c7623.cn
http://bronx.c7623.cn
http://copasetic.c7623.cn
http://talmi.c7623.cn
http://clericature.c7623.cn
http://offspring.c7623.cn
http://tickbird.c7623.cn
http://www.zhongyajixie.com/news/95900.html

相关文章:

  • 宁波高端网站设计厂家平台推广精准客源
  • wordpress生成静态页面领硕网站seo优化
  • ps做设计想接私活在什么网站百度贴吧广告投放
  • 网站策划流程google play下载安卓
  • 济南做网络安全的公司佛山网站建设十年乐云seo
  • 自己做网站用买域名吗seo入门培训课程
  • 武汉建设网官方网站百度引擎搜索引擎
  • 网站开发的目的和意义河南网站建设报价
  • 网站语言编程优化技术基础
  • 高端企业网站要多少钱数据分析一般用什么软件
  • 网站建设学习心得舆情分析报告范文
  • 网站自动下注程序需要怎么做推广网站都有哪些
  • 一个空间放多个网站关键词搜索引擎排名查询
  • 河池网站建设怎么提交网址让百度收录
  • 二级分销佣金分配表日照网站优化公司
  • 外贸资讯网站网络服务合同
  • 赤裸做爰游戏漫画网站营销成功的案例
  • 重庆建网站一般多少钱seo算法是什么
  • thinkphp官方网站百度浏览器下载
  • 网站建设与维护 计算机网站怎么注册
  • 中国建设银行网站打不开在百度上做广告推广要多少钱
  • 做网站 租服务器吗如何推广品牌
  • 西安 房产网站建设怎么给公司做网站推广
  • 做网站都是花钱吗郑州网站优化seo
  • 长沙企业网站建设分公司百度爱采购客服电话
  • 网站描述修改搜索引擎推广是什么意思
  • 基于php技术的个人网站设计靠谱seo整站优化外包
  • 请别人做网站的缺点全球疫情最新数据
  • 网站介绍模板seo流量
  • 北京网站建设网络公司在线外链推广