2

I understand it is not recommended, but I was curious about including the code for an SVG in image_data which would replace image per opensea's metadata standards page. This:

{
  "description": "Friendly OpenSea Creature that enjoys long swims in the ocean.", 
  "external_url": "https://openseacreatures.io/3", 
  "image": "https://storage.googleapis.com/opensea-prod.appspot.com/puffs/3.png", 
  "name": "Dave Starbelly",
  "attributes": [ ... ]
}

is their example of OpenSea-compliant metadata. So would I be able to do something like:

{
  "description": ..., 
  "external_url": ..., 
  "image_data": "
    <svg xmlns='http://www.w3.org/2000/svg'>
      <rect width='300' height='300'/>
    </svg>
  ", 
  "name": ...,
  "attributes": [ ... ]
}

Or would I have to encode or something else? thanks.

1
  • Did you find the answer after all? Commented Jun 22, 2023 at 17:32

2 Answers 2

1
+50

Your assumption is correct; you don't need to encode more of the SVG, just the raw data.

My only additional suggestion is to put everything on the same line, in case you edited the SVG manually, avoiding different ways to create new lines in a text file (carriage returns, new line feeds, etc.).

{
  "description": ..., 
  "external_url": ..., 
  "image_data": "<svg xmlns='http://www.w3.org/2000/svg'> <rect width='300' height='300'/> </svg>", 
  "name": ...,
  "attributes": [...]
}

You can watch an interesting video explaining "How to store NFT metadata and SVG image completely on-chain (ERC721/ERC1155)". It's an end-to-end tutorial, from the smart contract to viewing the NFT on testnet through OpenSea.

As a reference, here the differences between the image and the image_data attributes:

image: This is the URL to the image of the item. Can be just about any type of image (including SVGs, which will be cached into PNGs by OpenSea), and can be IPFS URLs or paths. We recommend using a 350 x 350 image.

image_data: Raw SVG image data, if you want to generate images on the fly (not recommended). Only use this if you're not including the image parameter.

2
  • I will happily mark this answer as accepted if you could explain what is the difference between image and image_data? Commented Jun 24, 2023 at 19:39
  • Sure, I added some notes, even though it seems to me the question is about the correct format to use for the value of the image_data attribute, more than the differences between image and image_data. Commented Jun 25, 2023 at 10:19
0

Here's an example of an NFT I've gotten to display on Opensea from straight SVG data, using image_data. Check out the encoding contract here. I used https://www.base64decode.org/ to ensure encoding worked as intended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.