PHP code example of hxfjsw / merkletreephp
1. Go to this page and download the library: Download hxfjsw/merkletreephp library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hxfjsw / merkletreephp example snippets
use MerkleTreePhp\Buffer;
use MerkleTreePhp\MerkleTree;
use MerkleTreePhp\Options;
use Web3\Utils;
deb4dff122697b0'
];
$leafNodes = array_map(fn($address) => Utils::sha3($address), $whitelistAddress);
$options = new Options();
$options->sortPairs = true;
$hashFn = fn(Buffer $bf) => Buffer::fromHex(Utils::sha3('0x' . $bf->toHex()));
$merkleTree = new MerkleTree($leafNodes, $hashFn, $options);
$root = $merkleTree->getHexRoot();
echo "root:" . $root . PHP_EOL;
$leaf = $whitelistAddress[0];
echo "leaf:" . $leaf . PHP_EOL;
$proof = $merkleTree->getHexProof(Utils::sha3($leaf));
echo "proof:" . json_encode($proof) . PHP_EOL;