0

I have a private blockchain using PoA and would like to store data in the data field of a transaction. To my understanding, the data field has a 32-byte limit and needs to be hex encoded. Is this assumption correct?

If so, what functions could I use from ethersjs to hash a file of arbitrary size into a 32-byte hex string? Thanks.

5
  • The data field of a transaction indicates what function-call (function name and parameters) should be executed in the transaction. How exactly does hashing a file fit into this??? The transaction will likely revert, unless somehow miraculously, the file will be hashed into a valid function-call AND that function is viable within the byte-code deployed at the address that you pass in the to field. May 25, 2020 at 14:07
  • Wow I realized I mistook the data field in transactions for the genesis data field. This would seem silly in retrospect.
    – Alejandro
    May 25, 2020 at 14:24
  • In conclusion, you can't store data in transactions, correct? I don't see how else you could accomplish that.
    – Alejandro
    May 25, 2020 at 14:24
  • 1
    Of course, you can pass the file to a smart contract and store it there. You don't need to hash the file, but if it's too large then the transaction might exceed the block size and will threrefore not be executed. May 25, 2020 at 14:31
  • Right. Contracts therefore are the right way to store non-transactional information in a blockchain (though they can also execute transactions). I will add this as the answer if you don't mind.
    – Alejandro
    May 25, 2020 at 14:56

1 Answer 1

1

The data field of a transaction indicates what function-call (function name and parameters) should be executed in the contract deployed at the address indicated by the to field of the transaction.

Passing the hash of some random data (a file in your example), will likely just cause the transaction to revert, because no such function will be viable at the destination address.

You can implement a contract with a function which receives this file as input and stores it in the contract.

Then, you'll need to execute one transaction in order to deploy that contract, and another transaction in order to execute that function.

Note that the file doesn't need to be hashed for this specific purpose, but of course, it may cause the transaction to be executed slower (since miners opt for small transactions), or event revert (if it is larger than the current block limit).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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