Is there any rust crate available for building merkle tree?

I have an vector or numbers. I need to build a merkle root out of it. Is there any crate available for this purpose?

Does merkletree provide what you are after?

I have gone through it, but i could't find anything that can convert a vector of elements into merkle leaf

Isn't that just MerkleTree::new(elements)? Assumption based on this function from merkletree's test suite.

merkle trees have a wide variety of incompatible definitions from different block chains. It's kind of a choose your own adventure situation.

error[E0277]: the trait bound `std::string::String: Element` is not satisfied
   --> src/main.rs:75:22
    |
75  |     let merkle_tree= MerkleTree::new(cid_vec);
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Element` is not implemented for `std::string::String`
    |
    = help: the trait `Element` is implemented for `[u8; 32]`

I have a vector of String

Transform your string into [u8; 32]. E.g. with a hash function.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.