How to use MerkleProof library?

I’m trying to use MerkleProof.sol.
Once imported, I write Using MerkleProof for ?
What I have to specify there?
Thanks!
:computer: Environment

OpenZeppelin v3.0.1
Truffle v5.1.24
Ganache-cli v6.9.1
:memo:Details

I’m getting the following error:
Undeclared identifier ==> verify()
:1234: Code to reproduce

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/cryptography/MerkleProof.sol";


contract MyContract {

    Using MerkleProof for <?>;
    constructor()
        public
    {}

function claim(bytes32[] memory proof, bytes32 root) returns (bool) {
         require(verify(proof, root, keccak256(abi.encodePacked(msg.sender))), "Caller is not a claimer");
return true;
}
 
}
1 Like

Found it!

pragma solidity ^0.6.0;

import "@openzeppelin/contracts/cryptography/MerkleProof.sol";


contract MyContract {

    Using MerkleProof for bytes32[];
    constructor()
        public
    {}

function claim(bytes32[] memory proof, bytes32 root) returns (bool) {
         require(proof.verify(root, keccak256(abi.encodePacked(msg.sender))), "Caller is not a claimer");
return true;
}
 
}
2 Likes

Hi @naszam,

Glad you were able to resolve. :partying_face:

Usually good places to look are: the documentation, the contract and the tests.

Documentation: https://docs.openzeppelin.com/contracts/3.x/api/cryptography#MerkleProof

Contract: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.1/contracts/cryptography/MerkleProof.sol

Tests: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.1/test/cryptography/MerkleProof.test.js

2 Likes

A post was split to a new topic: What to provide in the proof parameter of the verify function for the MerkleProof library