gpt4 book ai didi

why and when is setApprovalForAll called?(为什么以及何时调用setApprovalForAll?)

转载 作者:bug小助手 更新时间:2023-10-24 19:05:35 25 4
gpt4 key购买 nike



I'm having a hard time understanding why and when SetApprovalForAll is called on NFT generating contracts.

我很难理解为什么以及何时在NFT生成合同时调用SetApprovalForAll。


Take Cool Cats, for example. And for convenience there's a screen shot of relevant transactions, below.

以酷猫为例。为方便起见,下面是相关交易的屏幕截图。


I've noticed that for this contract and others, Set Approval For All is repeatedly called. In my own limited experience with a contract that allows minting, via _safeMint, I'm seeing a SetApprovalForAll transaction in the logs too. It's not called directly in my code.

我注意到,对于这份合同和其他合同,Set Approval for All被反复调用。在我有限的经验中,我使用了一个允许通过Via_SafeMint创建的契约,我在日志中也看到了一个SetApprovalForAll事务。它不会在我的代码中直接调用。


Why is it being called? Are wallets doing it as part of the minting process?

为什么要叫它?钱包这样做是铸币过程的一部分吗?


enter image description here


更多回答

Hi, i can i ask you something related to your question? in the setApprovalForAll it is asking me to pass an operator (which is supposed to be an address). does this mean i should pass all the wallet addresses manual?

嗨,我能问你一些与你的问题有关的问题吗?在setApprovalForAll中,它要求我传递一个操作符(应该是一个地址)。这是否意味着我应该通过所有的钱包地址手册?

优秀答案推荐

When you sell NFTs on a Marketplace, you need to authorize this marketplace to transfer sold items from your address to the buyer's address.

当您在Marketplace上销售NFT时,您需要授权该Marketplace将已售出的物品从您的地址转移到买家的地址。


This is what SetApprovalForAll is used for: because you trust the marketplace, you "approve" it to sell your NFTs (not all your NFTs, but the NFTs you own in the context of this contract).

这就是SetApprovalForAll的用途:因为您信任市场,所以您可以“批准”它来销售您的NFT(不是您的所有NFT,而是本合同上下文中您拥有的NFT)。


The marketplace is what is called the "operator" in the context of this API.

在此API的上下文中,市场就是所谓的“运营商”。



this is openzeppelin ERC721.sol

这是openzeppelin ERC721。


setApprovalForAll calls this function:

SetApprovalForAll调用此函数:


// Approve `operator` to operate on all of `owner` tokens
function _setApprovalForAll(
address owner,
address operator,
bool approved
) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}

_operatorApprovals is a mapping:

_OPERATOR APPROVIES是一个映射:


// owner address allows operator address
mapping(address => mapping(address => bool)) private _operatorApprovals;


An operator is a third party that is trusted and can be approved by an
owner to have access to all the NFTs owned by them. If an owner gives
permission to an operator, that operator is allowed to withdraw any
NFT from that owner's address and they are allowed to transfer it to
themselves or others.



更多回答

Why do you need to authorise the marketplace to transfer ALL your NFTs (in the context of that contract) even when you only want to list a single NFT for sale? I tested this on NFTrade. I went to list one NFT that I own, and it wants to call setApprovalForAll(). Even if I do trust them, why should I give them more permissions than needed? They should be able to send an NFT for me by just having me call approve() on a single token ID. Am I missing something?

为什么您需要授权市场转让您的所有NFT(在该合同的上下文中),即使您只想要列出一个NFT出售?我在NFTrade上对此进行了测试。我列出了我拥有的一个NFT,它想要调用setApprovalForAll()。即使我信任他们,我为什么要给他们更多的权限呢?他们应该能够为我发送NFT,只需让我对单个令牌ID调用Approve()。我是不是遗漏了什么?

There is a cost associated with setApprovalForAll, so maybe they thought it was more cost effective to set it once per collection contract

有一个与setApprovalForAll相关的成本,所以他们可能认为每个收款合同设置一次会更具成本效益

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com