Following Q/A (What datatype should I use for an IPFS address hash?) recommend us to use bytes to store IPFS hash.
I was using following example(https://github.com/AdrianClv/ethereum-ipfs/blob/master/NotSoSimpleStorage.sol), which uses string to store IPFS hash that costs around 110,000 gas price, which seems pretty expensive.
[Q] Does using bytes instead of string in order to store IPFS hash cost cheaper? I observe that storing bytes instead of string costs very close to string (110,000 gas). Since both datatypes storage seems expensive should I use events to store them?
Is there any example/tutorial related to store IPFS hash using bytes?
Would this work:
myContract.insertHash("QmWmyoMoctfbAaiEs2G46gpeUmhqFRDW6KWo64y5r581Vz");
contract Example_bytes {
bytes[] list;
function insertHash(bytes ipfsHash) {
list.push(ipfsHash); //costs around 110,000 gas.
}
}
contract Example_string {
struct hashes{
string hash;
}
hashes[] list;
function insertHash(string ipfsHash) {
list.push(hashes{hash: ipfsHash); //costs around 110,000 gas.
}
}
12207D5A99F603F231D53A4F39D1521F98D2E8BB279CF29BEBFD0687DC98458E7F89. Here(http://codebeautify.org/string-hex-converter) when I convertQmWmyoMoctfbAaiEs2G46gpeUmhqFRDW6KWo64y5r581Vzinto hex I got much larger string as516d576d796f4d6f63746662416169457332473436677065556d687146524457364b576f3634793572353831567a. @MidnightLightning – alper Jun 02 '17 at 20:35uint8 function, why we need it and where could we use it? Thank you. @MidnightLightning – alper Jun 02 '17 at 20:490x51, "m" is0x6d, etc.). What I did is use a tool that does Base58-decoding and used that to get the actual number being represented by that Base58 string. – MidnightLightning Jun 02 '17 at 20:55uint8 functionis storing an unsigned integer value as the name "function" in that struct object. "Function" is probably not the best name for that since it's a special word in Solidity and other programming languages; I picked it because in the multihash standard, that's what they call that variable; the variable that tells you what hashing function was used for this particular record (e.g.0x12for "sha2"). I'll update my answer to not use that special word "function" to be more clear. – MidnightLightning Jun 02 '17 at 20:58