solidity - 使用 Solidity 0.8 中的代币 erc1155 进行安全传输

标签 solidity smartcontracts

我收到此错误 ERC1155:转移到非 ERC1155Receiver 实现者 当尝试转移到智能合约时,我发现了这个文档 https://docs.openzeppelin.com/contracts/4.x/api/token/erc1155但仍然不知道如何解决这个问题,我是否必须在我的持有者 token 1155 中抽象 IERC1155Receiver 接口(interface)

最佳答案

接收合约需要基于ERC-721实现onERC1155BatchReceived()函数定义。

pragma solidity ^0.8;

contract MyContract {
    function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes memory _data) external returns(bytes4) {
        // here you can (but don't have to) define your own logic - emit an event, set a storage value, ...

        // this is the required return value described in the EIP-721
        return bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"));
    }
}

关于solidity - 使用 Solidity 0.8 中的代币 erc1155 进行安全传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68662387/

相关文章:

solidity - 在测试网上使用 Remix 部署合约时出现问题

node.js - 我们可以在 NodeJS 中使用 Solidity 吗?

solidity - Everscale Solidity。如何与负责任的职能部门合作?如何等待回调?

ethereum - 使用智能合约功能从 Uniswap 获取货币对价格

ethereum - 以太坊合约变量的初始值是多少?

ethereum - 如何检测以太坊地址是否为 ERC20 代币合约?

javascript - 如何显示智能合约中的所有事件日志?

ethereum - 如何使用oracle在智能合约中获取不同代币的价格

ethereum - 在 Solidity 中实现指数衰减函数

python - bsc 通过钱包地址获取交易 Web3.py