本文档介绍了 ERC-6909 最小多代币接口及其相关接口和合约。
建议在 https://docs.openzeppelin.com/contracts/api/token/erc6909 上查看本文档 |
这组接口和合约都与 ERC-6909 最小多代币接口 相关。
该 ERC 由四个接口组成,这些接口履行不同的角色——接口如下:
IERC6909
: 原始 ERC6909 代币的基础接口。
IERC6909ContentURI
: 扩展了基础接口,并添加了内容 URI(合约和代币级别)功能。
IERC6909Metadata
: 扩展了基础接口,并添加了元数据功能,该功能为每个代币 ID 公开名称、符号和小数位数。
IERC6909TokenSupply
: 扩展了基础接口,并为每个代币 ID 添加了总供应量功能。
为 ERC 中定义的 4 个接口中的每一个提供了实现。
ERC6909
import "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";
ERC-6909 的实现。 参见 https://eips.ethereum.org/EIPS/eip-6909
函数
事件
IERC6909
错误
supportsInterface(bytes4 interfaceId) → bool
public如果此合约实现了 interfaceId
定义的接口,则返回 true。 有关如何创建这些 ID 的更多信息,请参见相应的 ERC 部分。
此函数调用必须使用少于 30 000 的 gas。
balanceOf(address owner, uint256 id) → uint256
public返回 owner
拥有的 id
类型的代币数量。
allowance(address owner, address spender, uint256 id) → uint256
public返回 spender
被允许代表 owner
支出的 id
类型的代币数量。
不包括 operator 额度。 |
isOperator(address owner, address spender) → bool
public如果 spender
设置为 owner
的 operator,则返回 true。
approve(address spender, uint256 id, uint256 amount) → bool
public为调用者的代币设置对 spender
授权 amount
的 id
类型的代币。 type(uint256).max
的 amount
表示无限制的授权。
必须返回 true。
setOperator(address spender, bool approved) → bool
public授予或撤销对调用者的代币的任何代币 ID 的无限制转移权限给 spender
。
必须返回 true。
transfer(address receiver, uint256 id, uint256 amount) → bool
public将 amount
的 id
代币类型从调用者的帐户转移到 receiver
。
必须返回 true。
transferFrom(address sender, address receiver, uint256 id, uint256 amount) → bool
public将 amount
的 id
代币类型从 sender
转移到 receiver
。
必须返回 true。
_mint(address to, uint256 id, uint256 amount)
internal创建 amount
的代币 id
并将其分配给 account
,方法是从 address(0) 转移它。
依赖于 _update
机制。
发出一个 transfer
事件,其中 from
设置为零地址。
此函数不是 虚拟 的,而应覆盖 _update 。 |
_transfer(address from, address to, uint256 id, uint256 amount)
internal将 amount
的代币 id
从 from
移动到 to
,而不检查授权。 此函数验证发送者和接收者都不是 address(0),这意味着它不能铸造或销毁代币。
依赖于 _update
机制。
发出一个 transfer
事件。
此函数不是 虚拟 的,而应覆盖 _update 。 |
_burn(address from, uint256 id, uint256 amount)
internal从 account
销毁 amount
的代币 id
。
依赖于 _update
机制。
发出一个 transfer
事件,其中 to
设置为零地址。
此函数不是 虚拟 的,而应覆盖 _update 。 |
_update(address from, address to, uint256 id, uint256 amount)
internal将 amount
的代币 id
从 from
转移到 to
,或者,如果 from
(或 to
)是零地址,则铸造(或销毁)。 对转移、铸造和销毁的所有自定义都应通过覆盖此函数来完成。
发出一个 transfer
事件。
_approve(address owner, address spender, uint256 id, uint256 amount)
internal将 amount
设置为 spender
在 owner
的 id
代币上使用的额度。
此内部函数等效于 approve
,可用于例如为某些子系统设置自动额度等。
发出一个 {Approval} 事件。
要求:
owner
不能为零地址。
spender
不能为零地址。
_setOperator(address owner, address spender, bool approved)
internal批准 spender
对所有 `owner’s 代币进行操作
此内部函数等效于 setOperator
,可用于例如为某些子系统设置自动额度等。
发出一个 {OperatorSet} 事件。
要求:
owner
不能为零地址。
spender
不能为零地址。
_spendAllowance(address owner, address spender, uint256 id, uint256 amount)
internal根据花费的 amount
更新 `owner
对 spender
的额度。
如果额度无限,则不会更新额度值。 如果没有足够的额度可用,则还原。
不发出 {Approval} 事件。
ERC6909InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 id)
errorERC6909InsufficientAllowance(address spender, uint256 allowance, uint256 needed, uint256 id)
errorERC6909InvalidApprover(address approver)
errorERC6909InvalidReceiver(address receiver)
errorERC6909InvalidSender(address sender)
errorERC6909InvalidSpender(address spender)
errorERC6909ContentURI
import "@openzeppelin/contracts/token/ERC6909/extensions/draft-ERC6909ContentURI.sol";
ERC6909 中定义的内容 URI 扩展的实现。
函数
ERC6909
事件
IERC6909
错误
ERC6909
contractURI() → string
public返回合约的 URI。
tokenURI(uint256 id) → string
public返回 id
类型的代币的 URI。
_setContractURI(string newContractURI)
internal为合约设置 contractURI
。
发出 ContractURIUpdated
事件。
_setTokenURI(uint256 id, string newTokenURI)
internal为给定类型的代币 id
设置 tokenURI
。
发出 URI
事件。
ContractURIUpdated()
event当合约 URI 更改时发出的事件。 有关详细信息,请参见 ERC-7572。
URI(string value, uint256 indexed id)
event参见 IERC1155.URI
ERC6909Metadata
import "@openzeppelin/contracts/token/ERC6909/extensions/draft-ERC6909Metadata.sol";
ERC6909 中定义的元数据扩展的实现。 公开每个代币 ID 的名称、符号和小数位数。
函数
ERC6909
事件
IERC6909
错误
ERC6909
name(uint256 id) → string
public返回 id
类型的代币的名称。
symbol(uint256 id) → string
public返回 id
类型的代币的股票代码。
decimals(uint256 id) → uint8
public返回 id
类型的代币的小数位数。
_setName(uint256 id, string newName)
internal设置给定类型的代币 id
的 name
。
发出 ERC6909NameUpdated
事件。
_setSymbol(uint256 id, string newSymbol)
internal设置给定类型的代币 id
的 symbol
。
发出 ERC6909SymbolUpdated
事件。
_setDecimals(uint256 id, uint8 newDecimals)
internal设置给定类型的代币 id
的 decimals
。
发出 ERC6909DecimalsUpdated
事件。
ERC6909NameUpdated(uint256 indexed id, string newName)
eventid
类型的代币的名称已更新为 newName
。
ERC6909SymbolUpdated(uint256 indexed id, string newSymbol)
eventid
类型的代币的符号已更新为 newSymbol
。
ERC6909DecimalsUpdated(uint256 indexed id, uint8 newDecimals)
eventid
类型的代币的小数位数值已更新为 newDecimals
。
ERC6909TokenSupply
import "@openzeppelin/contracts/token/ERC6909/extensions/draft-ERC6909TokenSupply.sol";
ERC6909 中定义的代币供应量扩展的实现。 单独跟踪每个代币 ID 的总供应量。
函数
[_update(from, to, id, amount)
](https://docs.openzeppelin.com/contracts/
- 原文链接: docs.openzeppelin.com/co...
- 登链社区 AI 助手,为大家转译优秀英文文章,如有翻译不通的地方,还请包涵~
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!