4

How can I change the last line in the following code to make it work?

contract University { 
    address public owner; 
    address public student; 
    bytes32 fName; 
    bytes32 lName; 
    bytes32 Studies; 
    bytes32 private caCertificate; 
    bytes32 ipfs_hash;

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

     modifier onlyOwner() { if (msg.sender == owner) _; } 
     modifier onlyOwnerOrStudent() { 
         if (msg.sender == owner || msg.sender == student) _; 

    .....
}

I get the error message:

Operator == not compatible with types address and bytes32

  • 1
    Can you include the part of the code where these variables get initialized? It seems like they are of different types, which is causing the error... – Shawn Tabrizi Jul 6 '18 at 18:36
  • contract University address public owner address public student bytes32 fName bytes32 lName bytes32 Studies constructor() public { owner = msg.sender; } modifier onlyOwner() { if (msg.sender == owner) _; } modifier onlyOwnerOrStudent() { if (msg.sender == owner || msg.sender == student) _; } function setstudent () function getStudent (); event student( bytes32 fName, bytes32 lName, bytes32 Studies ); function checkStudentExists() public constant returns (bool) { if (student == lName) return true;} – bitcom Jul 6 '18 at 18:45
  • Code in comments is often unreadable due to formatting. (That code also seems to be mangled in other ways; it would not compile.) Please edit your question with the correct source code. – smarx Jul 6 '18 at 20:06
  • contract University { address public owner; address public student; bytes32 fName; bytes32 lName; bytes32 Studies; bytes32 private caCertificate; bytes32 ipfs_hash; constructor() public { owner = msg.sender; } modifier onlyOwner() { if (msg.sender == owner) _; } modifier onlyOwnerOrStudent() { if (msg.sender == owner || msg.sender == student) _; – bitcom Jul 6 '18 at 20:07
  • function setstudent (); function getStudent (); event student( bytes32 fName, bytes32 lName, bytes32 Studies, bytes32 ipfs_hash ); function checkStudentExists() public constant returns (bool) { if (student == lName) return true; } – bitcom Jul 6 '18 at 20:08
1

you are comparing data types of address and bytes32 for equality. Since they are two data types operator is not allowed. you need make either student to bytes32 or fName to address depending on your use-case.

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.