Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 1.63 KB

File metadata and controls

60 lines (42 loc) · 1.63 KB

第31讲(ERC1155)

ERC1155允許一個合約同時有FT跟NFT

每一種代幣都有一個id作為唯一標誌,每個id對應一種代幣

每種代幣(id)都會有對應的url

function uri(uint256 id) external view returns (string memory);

Event

TransferSingle: 單幣代幣轉帳事件

TransferBatch: 批量代幣轉帳事件

ApprovalForAll: 批量授權事件

URI: uri變更事件

Function

balanceOf: 單幣種餘額查詢

balanceOfBatch: 多幣種餘額查詢

setApprovalForAll: 批量授權

isApprovedForAll: 查詢批量授權狀態,看自己的account是否有授權給operator

safeTransferFrom: 安全單幣轉帳,若to是合約,會驗證是否有onERC1155Received接收函數

safeBatchTransferFrom: 安全多幣轉帳,若to是合約,會驗證是否有onERC1155BatchReceived接收函數

接收合約

  1. onERC1155Received: 單幣轉帳接收函數,並返回自己的function selector (0xf23a6e61)

需要返回 bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))

    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);
  1. onERC1155BatchReceived: 多幣轉帳接收函數,並返回自己的function selector (0xbc197c81)

需要返回 bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))

    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);