Solidity

solidity 函式在混音中完美執行,但在反應應用程序中它的執行方式不同

  • May 15, 2020

在 Remix 中,我執行它,它按我的預期工作,當我檢查其他函式的值時,它返回預期值

function makeadmin(string memory cityN, address adminAdress, string memory AdminName, 
string memory hash) public
   {
       require(msg.sender==0x20db1A3eD27EEF75BEBb000961d07AD47Bf58197);

       require(!(ch[cityN].AAdminAdress==adminAdress ));
        require(!(adminscitystatus[cityN]));
       require(!(adminsaddressstatus[adminAdress]));

       ch[cityN].CCityName=cityN;
       ch[cityN].AAdminAdress=adminAdress;
       ch[cityN].AAdminName=AdminName;

       ch[cityN].hashh=hash;
         ch[cityN].noofadmins.push(adminAdress);
       ch[cityN].adminsid[adminAdress]=ch[cityN].noofadmins.length-1;
     adminscitystatus[cityN]=true;
       adminsaddressstatus[adminAdress]=true;
       cityforcompany.push(cityN);
       uint comid=cityforcompany.length-1;
       companycityid[cityN]=comid;
   }

在 React js 中,它不會將值添加到solidity 合約中的各個變數,並且變數 res 返回類似 Result 的內容$$ $$proto.constructor 長度為 0

async SubmitData4 (e) {
     e.preventDefault();
     await window.ethereum.enable();
     var Acc= await web3.eth.getAccounts();


     console.log('acc',Acc);


     var res= await LandAbi.methods.makeadmin("muree","0x8057450DFC37633CF19fbaC32E1eF30E44B36007","muneeb","sdasere4e4fre").call({from: Acc[0]});

console.log("res",res);


}
  1. 為了實際執行事務,更改callsend
  2. 返回到鏈下的價值是交易的收據

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