x402AgentsToolsHub

Merkle Tree Builder

Build a keccak-256 sorted-pair merkle tree (OpenZeppelin convention) from a list of leaves and get the root plus a verification proof for any leaf — the standard construction for token airdrops and allowlists. Fully deterministic: same leaves, same root.

Worked examples

Three-address allowlist

GET /api/v1/security/merkle-tree?leaves=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266%0A0x70997970C51812dc3A010C7d01b50e0d17dc79C8%0A0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC

Result: 0xcb2689150ea8900d82344bc482ea07e7e54c8495d8c7623a964f0cfe1001b278

With proof for the first leaf

GET /api/v1/security/merkle-tree?leaves=alice%0Abob%0Acarol&proofFor=alice

Result: 0x3a536165c4a51a7fc40fbcf3c2524e84f424849a5aa8aebd59a3b071918b8e76

Amount rows (address amount)

GET /api/v1/security/merkle-tree?leaves=0xabc0000000000000000000000000000000000001%20100%0A0xabc0000000000000000000000000000000000002%20250

Result: 0x225c103657b84444fcd5929d19ac50a8141429c7c9d49c60efa057967c549800

Machine API (x402)

$0.003 / call

This tool is also a JSON API for AI agents. Requests without payment receive 402 Payment Required plus instructions; agents pay USDC on Base via the x402 protocol — no accounts, no API keys.

GET /api/v1/security/merkle-tree?leaves=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266%0A0x70997970C51812dc3A010C7d01b50e0d17dc79C8%0A0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC HTTP/1.1
Host: agentstoolshub.com

→ 402 (payment required, instructions in headers)
→ 200 (after X-PAYMENT header; JSON body below)

{
  "tool": "security/merkle-tree",
  "input": {"leaves":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266\n0x70997970C51812dc3A010C7d01b50e0d17dc79C8\n0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"},
  "result": { "value": 3, "answer": "0xcb2689150ea8900d82344bc482ea07e7e54c8495d8c7623a964f0cfe1001b278" }
}

Agent docs: /llms.txt · OpenAPI spec · integration guide

About this tool

Computes merkle roots and inclusion proofs exactly the way Solidity merkle-distribution contracts (OpenZeppelin MerkleProof, uniswap-style airdrops) expect: keccak-256 leaf hashing, sorted sibling pairs, duplicated last leaf on odd levels. Agents use it to build allowlists and verify claims without trusting a UI.

leaf = keccak256(leaf_bytes); parent = keccak256(sort(left, right))

Frequently asked questions

Which convention is this?

Sorted-pair keccak-256 — the OpenZeppelin-compatible construction: hash each leaf, then hash pairs in sorted order (last leaf is duplicated on odd levels). Verify on-chain with MerkleProof.verify().

How large a list can I use?

Up to 512 leaves per call on this API; for bigger trees build them locally — the construction is identical and only depends on the leaf list.

Related tools