Im writing a function in solidity where the user enters a CID from an IPFS link, which looks like:


So far im using string type, and it works.

Which is the correct and most efficient type for a CID? (int / uint?, bytes? )

 function storeCID(string memory cid) public returns (uint256){

// some login here...


1 Answer 1


I would say usually string. I think in terms of most efficient storage wise, converting it all the way into bytes would yield the lowest storage cost. Since IPFS cant be accessed through contracts though, it doesn't matter a ton. If the storage cost matters a lot to you depends a lot on your application and what you are doing with them. A lot of time, you will reconstruct the ipfs link using a prefix/suffix plus the content identifier.

In short, storing them as strings make them much easier for people to work with, but if you needed as much storage efficiency as possible for some reason, in theory converting the value to bytes would probably yield the lowest storage amount.

  • Thanks for your answer. Ok, so in my case it would be more efficient to use bytes as Im just storing CIDs. Then I build the full links from server/client...
    – Xunorus
    Nov 17 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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