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 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()`
}