function checkOffers() public returns (bool){
    uint256 a = sha256(offerFromProducer);
    uint256 b = sha256(offerFromConsumer);
    if(a == b){
        return true;
    return false;

enter image description here

Is there some method to compare two structs in Solidity?


The return value of sha256 is bytes32. So use bytes32 a = sha256(...) and do the same for b. This will fix the compiler errors and a == b will work.

But currently you cannot pass a struct to hashing functions like sha256, keccak256: https://github.com/ethereum/solidity/issues/980. So generally the members of the structs have to be compared against each other. A more specific question may help to uncover possible optimizations (for example, there may be ways to reduce the comparisons required depending on the app design).

  • Thanks! Can you give advice how to compare two structures with such fileds? struct Offer { uint amount; address transportCompany; string deliveryAddres; } Mar 1 '17 at 7:22

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.