Bitmaps Library example

Hi, do you have any resources on how to use the new Bitmaps library? I'd like to know exactly how to create a variable of that type and how to set / get it's values.
Thanks,

1 Like

Here is an example

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/utils/structs/BitMaps.sol";

contract Test {
  using BitMaps for BitMaps.BitMap;

    BitMaps.BitMap private bitmap;

    constructor() {
    }

  function get(uint index) public view returns (bool) {
    return bitmap.get(index);
  }

  function setTo(uint index, bool value) public {
    bitmap.setTo(index,value);
  }

  function set(uint index) public {
    bitmap.set(index);
  }

  function unset(uint index) public {
    bitmap.unset(index);
  }

}

Please note that, just like the EnumerableSet, EnumerableMap, and DoubleEndedQueue, this type can only exist in storage.

You cannot allocate it in memory, and you can't pass it as argument for public/external functions.