Skip to content
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

Does ERC721A work with NFT changing name? #375

Open
barbar150 opened this issue Jul 16, 2022 · 6 comments
Open

Does ERC721A work with NFT changing name? #375

barbar150 opened this issue Jul 16, 2022 · 6 comments

Comments

@barbar150
Copy link

No description provided.

@Vectorized
Copy link
Collaborator

Vectorized commented Jul 16, 2022

Yes!

function _setStringAtStorageSlot(string memory value, uint256 storageSlot) private {
    assembly {
        let stringLength := mload(value)

        switch gt(stringLength, 0x1F)
        case 0 {
            sstore(storageSlot, or(mload(add(value, 0x20)), mul(stringLength, 2)))
        }
        default {
            sstore(storageSlot, add(mul(stringLength, 2), 1))
            mstore(0x00, storageSlot)
            let dataSlot := keccak256(0x00, 0x20)
            for { let i := 0 } lt(mul(i, 0x20), stringLength) { i := add(i, 0x01) } {
                sstore(add(dataSlot, i), mload(add(value, mul(add(i, 1), 0x20))))
            }
        }
    }
}

function setName(string memory value) public {
    _setStringAtStorageSlot(value, 2);
}

function setSymbol(string memory value) public {
    _setStringAtStorageSlot(value, 3);
}

This is only for the regular ERC721A (non-upgradeable version), and make sure ERC721A is the first class you inherit.

Make sure to add an onlyOwner modifer to setName and setSymbol.

Another way is to simply override the name() and symbol() functions with the latest code in this repo.

@tareqbara
Copy link

@Vectorized this code lets the owner of the NFT change its name?

@Vectorized
Copy link
Collaborator

Please make sure that you use the onlyOwner modifier to only allow the contract owner to call those functions.

@tareqbara
Copy link

@Vectorized I understand, but will this function let the owner of the NFT change their NFT name? Like The SHIBOSHIS?

@Vectorized
Copy link
Collaborator

No.

That’s tokenURI.

@intenex
Copy link

intenex commented Jul 28, 2022

Just wanted to say thank you for providing this code! Super helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants