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

Add address to string conversion #3403

Merged
merged 13 commits into from May 13, 2022
Merged

Add address to string conversion #3403

merged 13 commits into from May 13, 2022

Conversation

pcaversaccio
Copy link
Contributor

@pcaversaccio pcaversaccio commented May 9, 2022

This PR adds a new function to the Strings library that converts an address to its ASCII string hexadecimal representation. The main motivation is the reason that I've encountered already multiple projects that use a sophisticated tokenURI strategy, that concatenates multiple attributes - one of which is an address - into a string. An example:

return string(abi.encodePacked(_baseTokenURI, toString(creator), "-", tokenId.toString()));

PR Checklist

  • Tests
  • Documentation => should be automatically added to Strings
  • Changelog entry

Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
@pcaversaccio pcaversaccio changed the title Add address to hex conversion Add address to string conversion May 9, 2022
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @pcaversaccio! I agree I can imagine this will be very handy for on-chain NFT metadata.

contracts/utils/Strings.sol Outdated Show resolved Hide resolved
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Amxx
Amxx previously approved these changes May 12, 2022
@Amxx
Copy link
Collaborator

Amxx commented May 12, 2022

Maybe we say that the produced address is not checksummed.

Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
@pcaversaccio
Copy link
Contributor Author

@Amxx good point - I added the comment! Somehow the CI actions don't work on this PR?

@frangio
Copy link
Contributor

frangio commented May 12, 2022

@pcaversaccio It may have been a GitHub problem.

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pcaversaccio! I made some small changes to the tests.

@frangio frangio enabled auto-merge (squash) May 13, 2022 18:34
@frangio frangio merged commit 5772512 into OpenZeppelin:master May 13, 2022
@pcaversaccio pcaversaccio deleted the feat/address-to-string branch May 13, 2022 18:53
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

Successfully merging this pull request may close these issues.

None yet

3 participants