I am getting the declaration error and I am not sure why. The error is in this line " function getSpaceAvailability(uint _space) view returns(bool) { return spaceDB[_space].spaceIsAvailable; }"

Here is the affected code -

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 < 0.9.0;

/// @title This contract will create an Air BNB type system 
/// @notice Development Purposes Only!
/// @dev Feel free to contribute or fix bugs or errors
/// @custom:experimental This is an experimental contract

* @title Setup the cUSD token contract interface
interface CUSDToken {
  function approve(address, uint256) external returns (bool);
  function balanceOf(address) external view returns (uint256);
  function transferFrom(address, address, uint256) external returns (bool);

contract celoBNB {
    // ***************
    // ***************
    // Define the addresses as 'payable' so we can send funds
    address payable lessorAddress;
    address payable leaseeAddress;

    // We define the home or apartment as a struct
    // We need to store the price, the Celo address of the current occupant
    // and if the space is available.
    struct space {
        uint256 pricecUSD;
        address currentOccupant;
        bool spaceIsAvailable;
    // For testing purposes we will assume the owner has 8 spaces to rent.
    // In production we would make this flexible
    // and allow the owner to add and remove spaces as desired
    space[8] spaceDB;
      /// @notice cUSD default contract address: 0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1
    address internal cUsdTokenAddress;
    // We'll use a modifier to limit who can call to the owner
    modifier ownerOnly() {
        require(msg.sender == lessorAddress);
        // We will run this once only when the contract is created
    constructor() public {
        // This stores the address that creates the contract as 'lessorAddress'
        lessorAddress = msg.sender;
        // Let's fill the array with test data
        // (all spaces available, even # spaces cost 1 cUSD, odd #s cost 2 cUSD)
        // We don't have to use but this gives us some testing data
        for (uint i=0; i<8; i++) {
            spaceDB[i].spaceIsAvailable = true;

    // ***************
    // GETTERS
    // ***************
    // This getter tells us if a space is available or not
    function getSpaceAvailability(uint _space) public view  returns(bool) {
        return spaceDB[_space].spaceIsAvailable;

    // This getter tells us the price of space
    function getPriceOfSpace(uint _space) public view  returns(uint256) {
        return spaceDB[_space].pricecUSD;

    // This getter tells us who's renting the space at the moment
    function getCurrentOccupant(uint _space) public view  returns(address) {
        return spaceDB[_space].currentOccupant;

    // ***************
    // SETTERS
    // ***************

    // This function sets the availability of a space
    function setSpaceAvailability(uint8 _space, bool _newAvailability) lessorOnly public {
        spaceDB[_space].spaceIsAvailable = _newAvailability;
        // if the space is to be set as "available", let's remove the current occupant
        // There is no 'null' in Solidity, and an address can't be set to 0 (type mismatch)
        // So we need to use address(0)
        if (_newAvailability) {
            spaceDB[_space].currentOccupant = address(0);
    // This function sets the price of the space
    // Can only be called by the lessor
    function setPriceOfSpace(uint8 _space, uint256 _priceInWei) lessorOnly public {
        spaceDB[_space].pricecUSD = _pricecUSD; 
    // This function handles the renting
    function rentASpace(uint8 _space) public payable returns(uint256) {

        // Look, a tenant!
        leaseeAddress = msg.sender;

        // Let's check if the tenant is sending the right amount
        // The modulo operator will be true if the amount is zero,
        // so we have to use &&
        if (msg.value % spaceDB[_space].pricecUSD == 0 && msg.value > 0 && spaceDB[_space].spaceIsAvailable == true) {

            // We calculate how many days the tenant has just paid for
            uint256 numberOfNightsPaid = msg.value / spaceDB[_space].pricecUSD;

            // Set the availability to false
            spaceDB[_space].spaceIsAvailable = false;

            // Set the tenant address in spaceDB
            spaceDB[_space].currentOccupant = leaseeAddress;

            // Send the rent to the owner

            // The function returns the number of days paid
            // You can use this info on the frontend
            return numberOfNightsPaid;
        // What is the tenant sent the wrong amount?
        // Well we send it back
        } else {
            // we send back the funds (minus gas)
            // we return 0 days;
            return 0;

2 Answers 2


In line 91 you are calling a modifier which is not declared!

function setSpaceAvailability(uint8 _space, bool _newAvailability) lessorOnly public {...}

Declare a modifier named lesserOnly


You have an extra } before the getters

}  // <<<<<------ Move to the end

    // ***************
    // GETTERS
    // ***************
    // This getter tells us if a space is available or not

  • Thanks a bunch but now I am getting an error "DeclarationError: Identifier not found or not unique." at this line - function setSpaceAvailability(uint8 _space, bool _newAvailability) lessorOnly public { spaceDB[_space].spaceIsAvailable = _newAvailability; if (_newAvailability) { spaceDB[_space].currentOccupant = address(0); } } Aug 29, 2021 at 1:59
  • @ShawnMichael That function isn't in the code you posted so I can't say for sure, but the idea is that you have to move the } after all the functions.
    – Ismael
    Aug 29, 2021 at 2:26
  • I have updated original post with full code. Aug 29, 2021 at 14:04
  • 1
    I want to thank you so much @Ismael. You have been a great help Aug 29, 2021 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.