0

I am getting the following Solidity error in my contract and I'm not sure what the problem is: Expected identifier but got '('

Here is my contract stripped down to the problem.

// SPDX-License-Identifier: MIT

// pragma solidity defines compiler version
pragma solidity ^0.8.10;

import '@openzeppelin/contracts/utils/Counters.sol';
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';

contract NFTMarket is ReentrancyGuard {
    using Counters for Counters.Counter;
    Counters.Counter private _itemIds;
    Counters.Counter private _itemsSold;

    address payable owner;
    uint256 listingPrice = 0.050 ether;

    constructor() {
        owner = payable(msg.sender);
    }

    function createMarketItem(
        address nftContract, uint256 tokenId, uint256 price
    ) public payable nonReentrant {
         _itemIds.increment();
         uint256 itemId = _itemIds.current();
    }

    IERC721(nftContract).safeTransferFrom(msg.sender, address.this, tokenId);
           ^
    Expected identifier but got '('
}

Does anybody have any idea how to resolve this properly?

Update: I didn't realize that I had it outside of the createMarketItem function. That fixed that error. However, it now says member this not found for address.this. Shouldn't that work for the contract address?

// SPDX-License-Identifier: MIT

// pragma solidity defines compiler version
pragma solidity ^0.8.10;

import '@openzeppelin/contracts/utils/Counters.sol';
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';

contract NFTMarket is ReentrancyGuard {
    using Counters for Counters.Counter;
    Counters.Counter private _itemIds;
    Counters.Counter private _itemsSold;

    address payable owner;
    uint256 listingPrice = 0.050 ether;

    constructor() {
        owner = payable(msg.sender);
    }

    function createMarketItem(
        address nftContract, uint256 tokenId, uint256 price
    ) public payable nonReentrant {
         _itemIds.increment();
         uint256 itemId = _itemIds.current();

         IERC721(nftContract).safeTransferFrom(msg.sender, address.this, tokenId);
    }
}

1 Answer 1

0

you need to use address(this) instead of address.this, address(this)` will return the address of the contract.

1
  • That did resolve the issue. Thank you!
    – M2 Learner
    Dec 10, 2021 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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