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.
}
}