10

Here is an IPFS hash: QmTfCejgo2wTwqnDJs8Lu1pCNeCrCDuE4GAwkna93zdd7d. According to IPFS docs, they are base58 encoded, and I assume the Qm is metadata (because they all share this).

What is the most effective datatype to store one of these?

Edit: they do not all start with Qm

7

bytes because they are more than 32 bytes. An IPFS hash:

itself specifies the hash function and length of the hash in the first two bytes of the multihash. In the examples above the first two bytes in hex is 1220, where 12 denotes that this is the SHA256 hash function and 20 is the length of the hash in bytes - 32 bytes.

Source

Although SHA2-256 is 32 bytes and currently the most common IPFS hash, other content could use a hash function that is larger than 32 bytes.

  • 1
    I'm sure this is the right answer for the general case but if the hash is created by your own software (ie you don't have to support arbitrary IPFS content) there may be an argument for committing to using 32-byte SHA2-256 hashes and stripping the multihash-identifying 1220, since arrays are a PITA to work with in Solidity, and in practice everyone is just going to be filling the blockchain up with 1220s. – Edmund Edgar Jan 25 '17 at 23:40
  • 1
    Certainly agree about PITA with some types. We should remember though IPFS highly values future-proofing (like github.com/multiformats/multihash). Maybe a library could help, as "it is also possible to extend elementary types". – eth Jan 29 '17 at 8:16

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.