我对 ERC-6909 的实施和规范有疑问。在标准中,对于多令牌 id,类型应为 unit256。有人可以使用相当于“uint256”的自定义类型作为令牌 ID 吗?换句话说,如果我们定义:
类型 XYZ 为 uint256;
并使用 XYZ 类型作为令牌 ID,它仍然合规吗?
https://eips.ethereum.org/EIPS/eip-6909
我联系了作者和以太坊基金会,但未能得到答案。
ERC-6909 标准实际上要求
uint256
类型作为代币 ID。
对标准内容的解释放在一边 - 从技术上讲,可以使用另一种可以 ABI 编码为
uint256
的类型。
例如下面的代码
pragma solidity 0.8.27;
contract MyContract {
type XYZ is uint256;
function tokenURI(XYZ id) external view returns (string memory) {}
}
生成 ABI,允许传递
uint256
参数的 id
值,即使类型是 XYZ
(扩展 uint256
)。
[
{
"inputs": [
{
"internalType": "MyContract.XYZ",
"name": "id",
"type": "uint256"
}
],
"name": "tokenURI",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
]