Hi everyone, I am a newbie at writing smart contract. I’ve just started playing around with Solidity and I had this really weird error that I do not know why.
I want to use a function that is already a built-in function in openzeppelin (for example, function safeTransferFrom(address, address, uint256, uint256, bytes) in ERC1155.sol). For specific purposes, I want to use this function (safeTransferFrom()) inside another function (for example, function test()). But as you can see, once I call the safeTransferFrom(), I just cannot write any code after that line (I tried in the hardhat/truffle console and I confirm this). For “after that line”, I mean, just inside the current function I am writing. I can write anything after that function, but not inside that function, after the line I used safeTransferFrom.
I have no idea why I got this “issue” (not sure it’s an issue, maybe I just don’t really understand the concept).
So do you have any idea or suggest about this one?
I got a picture of my code below to represent my problem. Thanks for your support! I really appreciate it!
It’s because with those functions they are returning things, so it ends your code execution when calling things like SafeTransfer - hence the name, it’s “safe” because after you call, that’s final. No other things can happen, which could mess with other things in your code.
Read the mint function that you are trying to do and show me what you find!
Yes, I did do some experiments.
I tried to change some global variables, and if I put those lines (that change the variables) after the safeTransfer function, these variables seemed to remain the same. Everything went right if I put those lines before the safe function one.
As your suggestion, I could understand that there is something that would be return after the _mint(). But literally, I don’t see any “return” here, this function is not marked as it would return anything (the definition don’t have the syntax e.g returns(uint256), there is not keyword return).
Can you please explain more about this?
Even more confusing when I put a random variable (e.g num in here, the code now have no warning “Unreachable code” at all D:)
I successfully update num’s value to 4:
Try to update num’s value and failed (got “Unreachable code” error):
After all, I found out that the contract works pretty well when I deployed it to the testnet (just have this current problem when I tried in hardhat/truffle console).
I’m still trying to figure it out, but I’m so confused and totally struggled.