Skip to content

Add address to string conversion#3403

Merged
frangio merged 13 commits into
OpenZeppelin:masterfrom
pcaversaccio:feat/address-to-string
May 13, 2022
Merged

Add address to string conversion#3403
frangio merged 13 commits into
OpenZeppelin:masterfrom
pcaversaccio:feat/address-to-string

Conversation

@pcaversaccio

@pcaversaccio pcaversaccio commented May 9, 2022

Copy link
Copy Markdown
Contributor

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>

@frangio frangio left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread contracts/utils/Strings.sol Outdated
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

Amxx commented May 12, 2022

Copy link
Copy Markdown
Collaborator

Maybe we say that the produced address is not checksummed.

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

Copy link
Copy Markdown
Contributor Author

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

@frangio

frangio commented May 12, 2022

Copy link
Copy Markdown
Contributor

@pcaversaccio It may have been a GitHub problem.

Comment thread contracts/utils/Strings.sol Outdated

@frangio frangio left a comment

Copy link
Copy Markdown
Contributor

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.

3 participants