0

can anyone let me know how to save data of a variable of my smart contract in javascript variable. for example if i have a function in my smart contract and that function returns some value now how do i save that value in my javascript variable.

var propertycontractaddress=propertycontract.at('0x691d3fb44bc81b5e420946a0aba3d1d0555c0715');

var total;

propertycontractaddress.GetTotalNoOfProperties(function(error,result){

if(!error){

total=result;

 }else{

 console.error(error);
    }
  })
  console.log(total);


for(var i=1; i<=total;i++){

var table = document.getElementById("ListedPropertyTable");


 var row = table.insertRow(1);

var cell1 = row.insertCell(0);

var cell2 = row.insertCell(1);

var cell3 = row.insertCell(2);

var cell4 = row.insertCell(3);

propertycontractaddress.GetId(i,function(error,result)

{

    if(!error)

    {

    cell1.innerHTML = result;

console.log(result);

}

    else

    {

console.error(error);

}

});

propertycontractaddress.GetPrice(i,function(error,result)

{

if(!error)

{

cell2.innerHTML = result;

}

else

{

    console.error(error);

}

});

propertycontractaddress.GetType(i,function(error,result)

{

if(!error)

{

    cell3.innerHTML = result;

}

else

{

    console.error(error);

    }

});

propertycontractaddress.GetCityn(i,function(error,result)

{

if(!error)

{

    cell4.innerHTML = result;

}

else

{

    console.error(error);

}
                    });
}



 </script>
  • In Truffle: var x = await myContract.myFunc(). Or if you're on web3 1.x outside of Truffle, var x = await myContract.methods.myFunc().call(). – goodvibration Dec 26 '18 at 18:37
  • @goodvibration by myContract you mean the var myContract in which i have saved the contract address right? – Faheel Sattar Dec 26 '18 at 18:52
  • Can't really refer to that question, nor to your original question, without you posting your code first (which you should have done so anyway). – goodvibration Dec 26 '18 at 19:00
  • @goodvibration i have a GetTotalNoOfUsers function in a contract which returns me total no of users. Now i want to save total number of users in javascript variable. for example var a – Faheel Sattar Dec 26 '18 at 19:04
  • Post your code! (Please). – goodvibration Dec 26 '18 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.