![](/img/trans.png)
[英]How to check whether user has any ERC1155 of specific contract in solidity?
[英]How to fix "Unidentified contract"? OpenSea is unable to “understand” ERC1155
我已經部署了一個基於ERC-1155的合約(基於OpenZeppelin )並成功地在這個合約上鑄造了一些 NFT。 但是當我想在 OpenSea 中使用這些 NFT 時,它總是說“Unidentified contract” 。
示例: https ://testnets.opensea.io/assets/0xc7d3e4a5A0c3e14ba8C68ea1b8a99a9dBf3ca76F/2
API 示例: https ://testnets-api.opensea.io/api/v1/asset/0xc7d3e4a5A0c3e14ba8C68ea1b8a99a9dBf3ca76F/2/?force_update=true
在他們的官方教程存儲庫(由於過時的依賴項和其他問題而不再編譯)之后,我添加了一些(可能)OpenSea 特定的函數和數據,這些函數和數據可能需要 OpenSea 才能正常工作。 然而,OpenSea 能夠獲取顯示 NFT 所需的所有數據,但只要他們說“Unidentified contract”,到目前為止這一切都沒有意義。
我的問題是:
是否有人已經設法部署 ERC-1155 並將其與 OpenSea 一起正確使用而沒有此問題? 有什么我們必須以某種方式“注冊”不基於 ERC-721 的合同嗎?
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract OwnableDelegateProxy { }
contract ProxyRegistry {
mapping(address => OwnableDelegateProxy) public proxies;
}
contract MetaCoin is ERC1155, AccessControl, Pausable, ERC1155Burnable {
bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
address proxyRegistryAddress;
constructor(address _proxyRegistryAddress) ERC1155("https://abcoathup.github.io/SampleERC1155/api/token/{id}.json") {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(URI_SETTER_ROLE, msg.sender);
_setupRole(PAUSER_ROLE, msg.sender);
_setupRole(MINTER_ROLE, msg.sender);
proxyRegistryAddress = _proxyRegistryAddress;
}
function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) {
_setURI(newuri);
}
function pause() public onlyRole(PAUSER_ROLE) {
_pause();
}
function unpause() public onlyRole(PAUSER_ROLE) {
_unpause();
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC1155, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
function mint(address account, uint256 id, uint256 amount, bytes memory data)
public
onlyRole(MINTER_ROLE)
{
_mint(account, id, amount, data);
}
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
public
onlyRole(MINTER_ROLE)
{
_mintBatch(to, ids, amounts, data);
}
function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
internal
whenNotPaused
override
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-free listings.
*/
function isApprovedForAll(
address _owner,
address _operator
) public override view returns (bool isOperator) {
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}
return ERC1155.isApprovedForAll(_owner, _operator);
}
}
節點:v16.7.0
部門:
"@openzeppelin/contracts": "^4.3.0",
"@nomiclabs/buidler": "^1.4.8",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^2.1.1",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/hardhat-upgrades": "^1.9.0",
"@typechain/ethers-v5": "^6.0.5",
"@typechain/hardhat": "^1.0.1",
"@types/chai": "^4.2.15",
"@types/chai-as-promised": "^7.1.3",
"@types/mocha": "^8.2.2",
"@types/node": "^14.14.37",
"chai": "^4.3.3",
"chai-as-promised": "^7.1.1",
"chai-datetime": "^1.8.0",
"ethereum-waffle": "^3.3.0",
"ethers": "^5.4.5",
"hardhat": "^2.6.1",
"hardhat-typechain": "^0.3.5",
"ts-generator": "^0.1.1",
"ts-node": "^9.1.1",
"typechain": "^4.0.3",
"typescript": "^4.2.4"
我終於找到了根本原因! OpenSea 需要一個名為name
的公共屬性,以便顯示集合的正確名稱,而不是靜態標簽Unidentified contract 。
我在查看他們的參考代碼時遇到了這個問題(這取決於現在已經有 3 年歷史的MultiToken-Contract 實現,並且需要全部降級 Node 和其他工具才能構建它[降級到 Node 10 工作今天最適合我])。
這取自您合同中的name
。
對於 ERC-1155 令牌,添加公共變量name
string public name = "My Collection Name";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.