1

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 2

0

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

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.