Solidity

一直有這個錯誤,ParserError: Expected ‘;‘但得到了’}’

  • January 16, 2022
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract will {
   address owner;
   uint fortune;
   bool deceased;


   constructor() payable public {
       owner = msg.sender; //msg sender represent address that is begin calles
       fortune = msg.value;// msg value tell us much ether begin sent
       deceased =false;
         
   }
    
    //create modifier so that only person that can call the contract is the owner
       modifier onlyOwner {
        require (msg.sender == owner);
        _;
    }
   

   //create modifier so that only allocate fund if friends gramp deceased
       modifier mustBeDeceased {
        require (deceased ==true );
        _;
    }
   address payable [] familyWallets;


   //map tru inhertance
   mapping(address => uint) inheritance;

   //set inhertance for each address

   function setInheritance(address payable wallet, uint amount) public {
       //to add wallet to the family wallet .push

       familyWallets.push(wallet);
       inheritance[wallet] = amount;
   }

   //pay eeach family member besed on their wallet address
   function payout() private mustBeDeceased {
       //with a for loop you can loop through thing and set conditions
       for( i=0; i<familyWallets.length; i++ ) {
           familyWallets[i].transfer(inheritance[familyWallets[i]])
       }
   }
       
       //orcale switch simulation
   function deceased() public onlyOwner {
       isDeceased = true;
       payout();
   }     

}

您的契約存在多個問題,導致無法編譯。這是一個不會引發任何錯誤的版本。第一個問題(;必需)是針對該familyWallets[i].transfer行的。

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract Will {
   address owner;
   uint fortune;
   bool deceased;


   constructor() payable {
       owner = msg.sender; //msg sender represent address that is begin calles
       fortune = msg.value;// msg value tell us much ether begin sent
       deceased =false;
         
   }
    
    //create modifier so that only person that can call the contract is the owner
       modifier onlyOwner {
        require (msg.sender == owner);
        _;
    }
   

   //create modifier so that only allocate fund if friends gramp deceased
       modifier mustBeDeceased {
        require (deceased ==true );
        _;
    }
   address payable [] familyWallets;


   //map tru inhertance
   mapping(address => uint) inheritance;

   //set inhertance for each address

   function setInheritance(address payable wallet, uint amount) public {
       //to add wallet to the family wallet .push

       familyWallets.push(wallet);
       inheritance[wallet] = amount;
   }

   //pay eeach family member besed on their wallet address
   function payout() private mustBeDeceased {
       //with a for loop you can loop through thing and set conditions
       for(uint256 i=0; i<familyWallets.length; i++ ) {
           familyWallets[i].transfer(inheritance[familyWallets[i]]);
       }
   }
       
       //orcale switch simulation
   function declareDeceased() public onlyOwner {
       deceased = true;
       payout();
   }     

}

引用自:https://ethereum.stackexchange.com/questions/119096