Lesson 14: abi.encodePacked and bytes typecasting #1676
-
I wonder why do we typecast abi.encodePacked to bytes when abi.encodePacked is already returning bytes type?
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
abi.encodePacked returns bytes but it also saves space, like it would remove the unnecessary "0x000.." (example only) |
Beta Was this translation helpful? Give feedback.
-
That is redundancy, and the typecasting should be omitted IMHO. @alymurtazamemon Could you cross-check as well? |
Beta Was this translation helpful? Give feedback.
-
@adriadrop Yes, we can remove this and directly use like this: Base64.encode(
abi.encodePacked(
'{"name":"',
name(), // You can add whatever name here
'", "description":"An NFT that changes based on the Chainlink Feed", ',
'"attributes": [{"trait_type": "coolness", "value": 100}], "image":"',
imageURI,
'"}'
)
) Also this: string memory svgBase64Encoded = Base64.encode(
bytes(string(abi.encodePacked(svg)))
); to this: string memory svgBase64Encoded = Base64.encode(abi.encodePacked(svg)); |
Beta Was this translation helpful? Give feedback.
@adriadrop Yes, we can remove this and directly use like this:
Also this:
to this: