1

# Solidity Transaction code Error

Solidity Code

pragma solidity >=0.4.4 <0.6.0;



contract PetSharing {




    //마스터(러브펫) 지갑 
    struct LovePet {
        address lovepet;
        uint lovepetwallet;
    }



    mapping (address => LovePet) LovePeter;

    // 펫주인의 정보
    struct Owner {
        address owner;
        string ownerName;
        string petName;
        uint ownerprice;
        string petInfo;
        string petselltext;
        uint ownerwallet;
    }


    mapping (address => Owner) Owners;
    address[] public OwnerAddresses;

    //펫주인의 펫인증 이미지들
    struct Image {
        string petImageHash;
        string ipfsInfo;
    }

    mapping (address => Image[]) private images;

    //펫시터 정보들
    struct PetSitter {
        address petsitter;
        string petSittername;
        string petSitterInfo;
        string educationConfirm;
        string petsharetext;
        uint sitterprice;
        uint petsitterwallet;
    }

    mapping (address => PetSitter) PetSitters;
    address[] public PetSitterAddresses;

/*   constructor(address _MASTER) public {

       LovePeter[_MASTER].lovepet = msg.sender;

     } */

    //마스터 확인
    modifier MasterInfo(address _MASTER) {
        require(_MASTER == msg.sender);
        _;
    }

    //펫주인 확인 
    modifier OwnerModifyInfo(address _OWNER ) {
        require(_OWNER == msg.sender);
        _;

    }

    //펫시터 확인
    modifier PetSitterModifyInfo(address _PETSITTER) {
        require(_PETSITTER == msg.sender);
        _;

    }

    //master 
    function RegisterMaster(address _master) public {
        LovePeter[_master].lovepet = _master;
    }

    //펫주인 등록
    function RegisterOwner(address _owner, string _ownername, string _petname, string _petInfo) public  {
         //   var Owner = Owners[_owner];

            Owners[_owner].ownerName = _ownername;
            Owners[_owner].petName = _petname;
            Owners[_owner].petInfo = _petInfo;

            OwnerAddresses.push(_owner);

    }

    //펫시터 등록
    function RegisterPetsitter(address _petsitter, string _petsittername, string _petsitterinfo, string _education) public  {
     //  var PetSitter = PetSitters[_petsitter];

        PetSitters[_petsitter].petSittername = _petsittername;
        PetSitters[_petsitter].petSitterInfo = _petsitterinfo;
        PetSitters[_petsitter].educationConfirm = _education;

        PetSitterAddresses.push(_petsitter);
    }

    //펫주인들의 목록
    function getOwnerAddresses() view public returns (address[]) {
        return OwnerAddresses;
    }

    //펫 주인의 정보들
    function getOwnerInfo(address _owner) view public returns (string,string,string) {
        return(Owners[_owner].ownerName,Owners[_owner].petName,Owners[_owner].petInfo);
    }

    //펫 주인 숫자
    function OwnerCount() view public returns (uint) {
        return OwnerAddresses.length;
    }

    //펫시터들의 목록
    function getPetSitterAddresses() view public returns (address[]) {
        return PetSitterAddresses;
    }

    //펫시터들의 정보
    function getPetSitterInfo(address _petsitter) view public returns(string,string,string) {
        return (PetSitters[_petsitter].petSittername, PetSitters[_petsitter].petSitterInfo, PetSitters[_petsitter].educationConfirm);
    }

    //펫시터 숫자
    function PetSitterCount() view public returns (uint) {
        return PetSitterAddresses.length;
    }

    //펫 인증 정보를 블록체인 등록
    function uploadImage(string hash, string ipfs) public {
        images[msg.sender].push(Image(hash,ipfs));
    }

    //펫시터 돌봄서비스 글 등록
    function PetSitterShareText(address _PETSITTER, string _petsittertext)  PetSitterModifyInfo(_PETSITTER) public view returns(string) {
      //  var PetSitter = PetSitters[_sitter];
       _petsittertext  = PetSitters[_PETSITTER].petsharetext;
        return "정상적으로 등록되었습니다";
    }

    //오너 돌봄서비스 요청글 등록
    function OwnerShareText(address _OWNER, string _ownersharetext) OwnerModifyInfo(_OWNER) public view  returns(string){
        _ownersharetext = Owners[_OWNER].petselltext;
        return "정상적으로 등록되었습니다";
    } 

    //강아지 돌봄서비스 거래 (펫주인이 펫시터글 선택 했을때 or 펫시터가 펫주인글을 선택했을때)
    function TransactionPet(address _petsitter,address _OWNER )  OwnerModifyInfo(_OWNER) public payable {
        require(PetSitters[msg.sender].petsitterwallet >= PetSitters[_petsitter].sitterprice);
        require(PetSitters[_petsitter].sitterprice == msg.value);
    }


    //펫주인이 돌봄이 힘들때 펫시터에게 강아지를 판매 할때
   function PetChangeTransaction(address _ownerseller, address _PETSITTER, address _MASTER, uint _ownerpirce) MasterInfo(_MASTER) PetSitterModifyInfo(_PETSITTER) public  payable {
       // var Owner = Owners[_seller];
       _ownerpirce = Owners[_ownerseller].ownerprice;
    //   require(PetSitters[msg.sender].petsitterwallet >= Owners[_ownerseller].ownerprice);
       require(_ownerpirce == msg.value);
       PetSitters[msg.sender].petsitterwallet -= _ownerpirce;
       require(PetSitters[msg.sender].petsitterwallet + _ownerpirce >= PetSitters[msg.sender].petsitterwallet);
       require(LovePeter[_MASTER].lovepetwallet + _ownerpirce >= LovePeter[_MASTER].lovepetwallet);
       LovePeter[_MASTER].lovepetwallet += msg.value;
    }

    function PetChange(address _ownerseller, address _PETSITTER, address _MASTER, uint _ownerpirce) MasterInfo(_MASTER) PetSitterModifyInfo(_PETSITTER) public {
        _ownerpirce = Owners[_ownerseller].ownerprice;
        LovePeter[msg.sender].lovepetwallet -= _ownerpirce;
        require(Owners[_ownerseller].ownerwallet + _ownerpirce >= Owners[_ownerseller].ownerwallet);

       Owners[_ownerseller].ownerwallet += msg.value;
        Owners[_ownerseller].owner = PetSitters[_PETSITTER].petsitter;
    }
     function test(address _OWNER) OwnerModifyInfo(_OWNER) public view  returns(uint){

        return  Owners[_OWNER].ownerwallet;
    }

    function test2(address _MASTER) MasterInfo(_MASTER) public view  returns(uint){

        return LovePeter[_MASTER].lovepetwallet;
    }
}

code end..

  • The error message is "Transaction to PetSharing.PetChangeTransaction Error: VM error: revert. reverse The transaction has been exceeded to the initial state. Note: The constructor could be paid if you send value." How do I fix the error?

There are more questions. Please watch.

 function PetChangeTransaction( address _PETSITTER, address _master, uint _ownerpirce ) PetSitterModifyInfo(_PETSITTER) public  payable {
       // var Owner = Owners[_seller];
       require(PetSitters[msg.sender].petsitterwallet >= _ownerpirce);
       require(_ownerpirce == msg.value);
       PetSitters[msg.sender].petsitterwallet -= _ownerpirce;
       require(PetSitters[msg.sender].petsitterwallet + _ownerpirce >= PetSitters[msg.sender].petsitterwallet);
       require(LovePeter[_master].lovepetwallet + _ownerpirce >= LovePeter[_master].lovepetwallet);
       LovePeter[_master].lovepetwallet += msg.value;
    }

    function PetChange(address _ownerseller, address _petsitter, address _MASTER, uint _ownerpirce) MasterInfo(_MASTER) public {
        LovePeter[msg.sender].lovepetwallet -= _ownerpirce;
        require(Owners[_ownerseller].ownerwallet + _ownerpirce >= Owners[_ownerseller].ownerwallet);
        Owners[_ownerseller].ownerwallet += _ownerpirce;
        Owners[_ownerseller].owner = PetSitters[_petsitter].petsitter;
    }

There are no errors when compiling, but if you modify the code below, Warning will occur. Why does the PetChange function Warning occur when it does not differ from the msg,value in the PetChangeTransaction function above?

 function PetChange(address _ownerseller, address _petsitter, address _MASTER, uint _ownerpirce) MasterInfo(_MASTER) public {
         require(_ownerpirce == msg.value);
        LovePeter[msg.sender].lovepetwallet -= _ownerpirce;
        require(Owners[_ownerseller].ownerwallet + _ownerpirce >= Owners[_ownerseller].ownerwallet);
        Owners[_ownerseller].ownerwallet += msg.value;
        Owners[_ownerseller].owner = PetSitters[_petsitter].petsitter;
    }
  • Warning is browser/ballot.sol:178:33: Warning: "msg.value" used in non-payable function. Do you want to add the "payable" modifier to this function?
1

Your original question's error message is impossible and I assume it was copypasted wrong or something similar. Your append's picture shows the real error message.

Anyway, as Rick mentioned, the end part of the error message is just a guess (and usually a wrong guess). But the beginning of it is the important part: Transaction to PetSharing.PetChangeTransaction Error: VM error: revert. This tells you that the transaction was reverted.

Usually the transaction gets reverted due to some require statement not passing. So I suggest you go through all your require statements which get triggered with that function call and figure out which one causes the error. You can either try to debug the transaction or just comment out the require statements one by one and see when the error disappears.

  • Thank you so much. I sucess about This problem. It's by your favor. – samjamy Jan 12 at 6:28
0

Avoid to try to write on one of the cited function argument:

_ownerpirce = Owners[_ownerseller].ownerprice;

The error message you reported is unrelated: it is a guess of the compiler, which did not understand the situation, and so it results wrong.

EDIT

Looking at your code I find a lot of require strictly related to the value of that poor _ownerpirce. I suspect that they cannot pass because it’s value is not that you seems to need.

If should this fix don’t work alone (do not write on function arguments !) do a simple thing: comment out every require or assert in your function for a test and try again. If this work, reinsert them all one by one in order to find the problem.

Some variable is needed to be used instead your poor _ownerpirce!

  • When I saw Rick Park's answer, I commented on the part, but the error was the same. – samjamy Jan 12 at 4:57
  • I updated the answer for you. – Rick Park Jan 12 at 5:50
  • Thank you so much. I sucess about This problem. It's by your favor. – samjamy Jan 12 at 6:28
  • I added a question. Can you watch it again? – samjamy Jan 12 at 6:47
  • According to the rules you should mark as answered this question and open another one. Do it and I’ll try to help. – Rick Park Jan 12 at 7:46

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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