0

I am migrating the following smart contract to local Blockchain (Ganache). however when I run migrate it's giving me an error: ParserError: Identifier-start is not allowed at end of a number.0X0

how can I solve this issue?

Truffle v5.3.2 (core: 5.3.2) Node v10.24.0

// SPDX-License-Identifier: UNLICENSED
    pragma solidity >=0.4.24;
    
    import "./Owned.sol";
    
    contract ReReviews is Owned {
    
      // Structure to hold Review 
      struct Review {
        uint id;
        address reviewer;
        address visitor;
        string name;
        string comments;
        uint totalUpvotes;
        uint totalRewards;
        uint totalDownvotes;
        string ipfsHash;
      }
    
      // State variables to map the address
      mapping(uint => Review) public reviews;
      uint reviewCounter;
    
      //Events to capture Add Review
      event addReviewEvent(
        uint indexed _id,
        address indexed _reviewer,
        string _name,
        string _ipfsHash
        );
    
      // Events to capture viewing the Review
      event viewReviewEvent(
        uint indexed _id,
        address indexed _reviewer,
        address indexed _visitor,
        string _name,
        uint _totalUpvotes,
        uint _totalRewards,
        uint _totalDownvotes,
        string _ipfsHash);
    
    
      //Add a review
      function addReview(string memory _name, string memory _comments, string memory _ipfsHash) public {
        // a new review
        reviewCounter++;
    
        //store this review
        reviews[reviewCounter] = Review(
            reviewCounter,
            msg.sender,
            0X0,
            _name,
            _comments,
            0,
            0.000,
            0,
            _ipfsHash
          );
    
        // trigger the event
        addReviewEvent(reviewCounter, msg.sender, _name, _ipfsHash);
      }
    
      // fetch the number of reviews in the contract
      function getNumberOfReviews() public  returns (uint) {
        return reviewCounter;
      }
    
      // fetch and returns all reviews IDs available for visitor
      function getReviewsToView() public  returns (uint[] memory) {
        // we check whether there is at least one review
        if(reviewCounter == 0) {
          return new uint[](0);
        }
    
        // prepare intermediary array
        uint[] memory reviewIds = new uint[](reviewCounter);
    
        uint numberOfReviewsForVisit = 0;
        // iterate over reviews
        for (uint i = 1; i <= reviewCounter; i++) {
          // keep only the ID of reviews not reviewed yet
          // if (reviews[i].visitor == 0x0) {
            reviewIds[numberOfReviewsForVisit] = reviews[i].id;
            numberOfReviewsForVisit++;
          // }
        }
    
        // copy the reviewsID array into the smaller forReview array
        uint[] memory forReview = new uint[](numberOfReviewsForVisit);
        for (uint j = 0; j < numberOfReviewsForVisit; j++) {
          forReview[j] = reviewIds[j];
        }
        return (forReview);
      }
    
      // View a review & upvote/downvote it
      function viewReview(uint _id,uint _totalUp, uint _totalDown) payable public {
        // we check whether there is at least one review
        require(reviewCounter > 0);
        // we check whether the review exists
        require(_id > 0 && _id <= reviewCounter);
    
        // we retrieve the review
        Review storage review = reviews[_id];
        if(_totalUp == 1 ){
          review.totalUpvotes = review.totalUpvotes + 1;
          review.totalRewards = review.totalRewards + msg.value;
        }
        if(_totalDown == 1 ){
          review.totalDownvotes = review.totalDownvotes + 1;
          review.totalRewards = review.totalRewards - msg.value;
        }
        
        // we check whether the article has not already been sold
        //require(article.buyer == 0x0);
    
        // we don't allow the reviewer to upvote/downvote his own reviews
        require(review.reviewer != msg.sender);
    
        // keep visitor's information
        review.visitor = msg.sender;
    
        // the visitor can review the Reviews
        review.reviewer.transfer(msg.value);
    
        // trigger the event
        viewReviewEvent(_id, review.reviewer, review.visitor, review.name, review.totalUpvotes, review.totalRewards, review.totalDownvotes, review.ipfsHash);
      }
    
      //kill the smart contract
      function kill() onlyOwner public {
        selfdestruct(owner);
      }
    }
2
  • if you are using the 0x0 for an address try using address(0) instead Jul 25 at 12:01
  • the error is gone with address(0) however it gives me this error now. TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address". review.reviewer.transfer(msg.value); . this is in line 10 from bottom to top. Jul 26 at 4:04
0

For your first error you will need to use address(0) as your zero address (usually the throw away address or the null address) instead of 0x0 as that is an old and deprecated way in solidity 0.4.

for the second error you will need to state that the reviewer address as payable. Also you should do this for any address that you are going to send funds to via transfer or send methods.

your struct should become like this :

struct Review {
        uint id;
        address payable reviewer;
        address visitor; 
        string name;
        string comments;
        uint totalUpvotes;
        uint totalRewards;
        uint totalDownvotes;
        string ipfsHash;
      }

Another option would be to locally convert the address to payable when trying to send the funds to it via the payable conversion :

address payable reviewPayable = payable(address(review.reviewer));
reviewPayable.transfer(msg.value);
7
  • after making it payable it gives me lots of more errors. is there another solution if I don't make 0x0 to address(0). Jul 26 at 10:39
  • fix those errors then, you will need to make it payable for your transfer to work. Also, if you don't have serious limitations on solidity versions why not use the 0.8.x version instead of staying at 0.4. Jul 26 at 10:42
  • sure but the problem is I am using VSCode with truffle and Ganache it's using solc 0.5.16 . Jul 26 at 11:39
  • after making it payable I am getting this error on all msg.sender. Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested. Jul 26 at 11:41
  • @MuhammadYounas i added an other option to my answer, don't change the address in the struct but when trying to send cast the address to payable. try that and tell me if it works or not. Jul 26 at 13:21

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.