-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function beforeTokenTransfer #5146
Comments
Hi |
Thank you for this fast answer ! So here is my new code :// SPDX-License-Identifier: MIT import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; contract MyToken is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
function _update(address from, address to) internal virtual { Is it correct ? I have no error but this seems too easy |
your welcome
|
Too fast to say it's ready but it should be that easy though. Feel free to head to our Wizard where you can build a contract with a couple of option selection. The output is always secure. |
Hey @Wi77iame , good to know you are learning Solidity! Your contract will not work because:
I propose you to override the |
@0xneves, heads up that the function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override {
require(from == address(0), "SBTs are non-transferable");
super._beforeTokenTransfer(from, to, tokenId);
} The correct override would be: import {IERC721Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
...
function _update(address to, uint256 tokenId, address auth) internal override returns (address) {
address from = super._update(from, tokenId, auth);
if (from != address(0)) throw IERC721Errors.ERC721InvalidSender(from); // SBTs are non-transferrable
return from;
} This way, it's still possible to mint, since the |
Hello guys ! Thanks for your help. pragma solidity ^0.8.20; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; contract VeriBound_SBT is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
function _update(address to, uint256 tokenId, address auth) internal override returns (address) { With this new function _update, I don't know why, Remix underlines IERC721Errors. Before this, I wrote (without the underscore): function update(address from, address to) internal virtual { And it seemed to have work when I ran transactions. |
Nice call on reverting when it comes from a different address other than zero address. import {IERC721Errors} from "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
...
function _update(address from, address to, uint256 tokenId) internal override {
if (from != address(0)) throw IERC721Errors.ERC721InvalidSender(from); // SBTs are non-transferrable
super._update(from, to, tokenId);
} |
Make sure that you are not gonna use Users can still send to a random address, but burning is a good practice to lower the total supply, therefore raising the token price on charts. function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
} |
OK I think now I understand the goal of function _update and how I have to deal with. But Remix is going crazy with semicolon, when I ask RemixAI, it wants to put ";" at the end of // SBTs are non-transferrable |
Hello everybody,
I m new here and in Solidity and I try to learn. I have an issue with this function (_beforeTokenTransfer), here is the code :
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract SoulboundToken is ERC721 {
uint256 public nextTokenId;
}
Remix or VScode send me an error : "Function has override specified but does not override anything"
I don't understand why and how can I fix it
Could you please help me e-and explain me what to do and what is the matter ?
Thank you very much
William
The text was updated successfully, but these errors were encountered: