Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 970 Bytes

README.md

File metadata and controls

40 lines (27 loc) · 970 Bytes

MerkleTree

How to use

import Plutarch.MerkleTree (pmember)
import Plutus.MerkleTree (fromList, mkProof, rootHash, member)
import Data.Maybe (fromJust)
import PlutusTx qualified
import Plutarch.Prelude
import Utils

-- Create your MerkleTree
myMerkleTree = fromList ["a","b","c","d","e","f","g","h","1","2","3","4"]

-- Create your Proof for "e" member
myProof = fromJust $ mkProof "e" myMerkleTree

-- Extract the Root Hash from MerkleTree
root = rootHash myMerkleTree

Plutarch On Chain

pmyProof = pmap # plam (\x -> pdata x) #$ pconstant myProof

evalT $ pmember # (pconstant "e") # (pconstant root) # pmyProof

Haskell On Chain

member (PlutusTx.Prelude.encodeUtf8 "e") root myProof

This library takes the PlutusTx code from the Hydra project, developed and maintained by Input Output Hong Kong (IOHK).

The repository can be found at https://github.com/input-output-hk/hydra/tree/master/plutus-merkle-tree