Add an Image to an NFT with Token Metadata

InstructorRyan Harris

Share this video with your friends

Send Tweet

Let’s add an image to our SVG. We’ll start by creating a base 64 encoded SVG using Base64 and OpenZeppelin.

Then, in order to actually associate an image to our token, we’ll have to apply it to our token’s metadata. We’ll create a base64 JSON object that includes our image, save it as a string variable that lives in memory, then call the _setTokenURI method with our NFT’s ID and our metadata string.

~ 3 years ago

Hi Ryan! For [1:54] I can't find any info on how to get the Base64.sol implementation in the lesson notes. Am I missing something?

Panagiotis Thomoglou
~ 3 years ago

Hi, I couldn't find it either. You could use another working library here https://gist.github.com/hellopath/6f7cd754fbcd45653946095e857f7c7e

Ryan Harrisinstructor
~ 3 years ago

Hey, y'all! So sorry I forgot to include that info. Here are some links:

  • UI starter repo: https://github.com/ryancharris/nftix-demo-ui
  • Base64: https://gist.github.com/ryancharris/ed5c4f161f2ab049adf41a7f3eed2229
  • Final smart contract: https://gist.github.com/ryancharris/b1be47faf3f141f21fbd5b42c80da2e3
~ 3 years ago

what extension do you have to for reading json?

~ 3 years ago

Running into issues with _setTokenURI probably because of this:

https://forum.openzeppelin.com/t/function-settokenuri-in-erc721-is-gone-with-pragma-0-8-0/5978/2

Am I the only one?

~ 2 years ago

i got a error : string memory encodedImage = Base64.encode(bytes(image));

Invalid type for argument in function call. Invalid implicit conversion from bytes memory to string memory requested.

Lucas Minter
~ 2 years ago

Hey. Here is a forum post about implicit conversion from string memory to bytes memory requested. Hopefully, this should answer your error: https://ethereum.stackexchange.com/questions/69055/solidity-invalid-implicit-conversion-from-string-memory-to-bytes-memory-requeste.