I previously created this topic, but was pointed to the OZ telegram (which is no longer running from what I saw). I am wondering what the best practice is for editing Open Zeppelin imported files? For example, if I am importing ERC20 from Open Zeppelin, but I want to make the transfer function payable, I would go into Open Zeppelin's ERC20 file and change the function in the file. What I am confused about now is, do I import the file in my smart contract like normal?
ex.
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
Or should I include the whole file within my smart contract (by copy pasting the code)?
In your case, maybe you can write a new function to do this, e.g.
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyContract is ERC20 {
constructor() ERC20("NAME", "SYMBOL"){}
function transferWithValue(address to, uint256 amount) public payable returns (bool) {
xxx; // do with `msg.value`
// Copy logic of `transfer`
_transfer(msg.sender, to, amount);
return true;
}
function transfer(address to, uint256 amount) public override returns (bool) {
revert();
}
// Same for `transferFrom()`
}
I haven't worked specifically with modifying OpenZeppelin imports, but I understand that editing the library files directly isn't the best approach since it could cause issues with upgrades and maintenance. Instead, writing a wrapper contract or extending the functionality with a new function seems like a cleaner way to handle it. I've seen similar discussions where people recommend creating a separate function instead of trying to override a non-payable function to a payable one.
This is unrelated, but if you're dealing with video formats in any of your projects, converting MJPEG files is easy with this MJPEG converter. It works with many different formats, so it's handy for compatibility issues. Check this link here for more info: https://www.movavi.com/video-converter/mjpeg-converter.html