I'm using ERC1155 and I want NFT in my contract that cannot be transferred in a specific condition. If I use override for _transferFrom, It will override new logic, and old logic will be lost. I just want to add some conditions to the function. How can I do that?
2 Answers
after you override the function within your contact,
you can use the keyword super
to call the old logic
https://docs.soliditylang.org/en/v0.8.17/contracts.html?highlight=super#inheritance
You can create new function in your own contract and make use of interfaces to use ERC-1155 predefined contract functionalities.
For example:
function _transferFrom(address owner, address contract1155, address from, address to, uint256 id, uint256 amount, bytes data) public {
require(msg.sender == owner, "Function could be called by owner only");
IERC1155(contract1155).safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes data);
}
Here we added our own require check which check whether the call is made by owner of contract or not and then uses erc-1155 method to transfer tokens by extends the erc1155 functionality extended.
'override' keyword is used when we want to preserve the function signature and want to change the logic only.