简体   繁体   English

你可以让 ERC1155 合约收到 ERC721 代币吗?

[英]Can you make an ERC1155 contract receive an ERC721 token?

I've got an ERC1155 contract and I want it to receive an ERC721 token and give other tokens in exchange for that.我有一个 ERC1155 合约,我希望它接收一个 ERC721 代币并提供其他代币作为交换。 Can I somehow add ERC721 Receiver interface?我可以以某种方式添加 ERC721 接收器接口吗?

Yes you can do that.是的,你可以这么做。 It would be best to start looking here at OpenZeppelins documentation on it: https://docs.openzeppelin.com/contracts/2.x/api/token/erc721#IERC721Receiver最好从这里开始查看 OpenZeppelins 文档: https ://docs.openzeppelin.com/contracts/2.x/api/token/erc721#IERC721Receiver

In your method that accepts ERC721 tokens, you will need to make sure that the sender approves your contract to transfer tokens on their behalf or else the transaction will fail.在您接受 ERC721 代币的方法中,您需要确保发件人批准您的合约以代表他们转移代币,否则交易将失败。

In conjunction with IERC721Receiver you have to use the safeTransferFrom method for this to work properly.IERC721Receiver结合使用,您必须使用safeTransferFrom方法才能正常工作。

hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM