3

My contract is:

   contract changeName{
    string customerName;

    function changeName(string _customerName)
       {
          customerName=_customerName;
       }

    function getName() returns(string)
       {

         return customerName;
       }
    }

In Javascript(meteor.js):

//contractAddress= block address where contract is deployed
//AbiArray : When contract is compiled 
var myContract= web3.eth.contract(AbiArray).at(contractAddress);

myContract.getName(function(err,res)
{
alert(res);
//getting block address here
//How to get function return value

});
  • Can you kindly reformat the question using Edit as now it has some formatting errors making it hard to read. – Mikko Ohtamaa Mar 15 '17 at 11:30
1

you could define the get function as constant and in your js code use :

 var contractInstance = MyContract.at('contract_address');
  var variable= contractInstance.getName(); 
  • Thank You ! But I'm getting an exception : The metamask web3 object does not support synchronous method like eht_call without callback parameter. – Avinash Vazratkar Mar 16 '17 at 9:17
  • Is there any alternative to metamask? I mean how to connect with Ethereum Blockchain without metamask? – Avinash Vazratkar Mar 16 '17 at 9:32
  • Use mist instead of metamask – Badr Bellaj Mar 16 '17 at 12:26
0

Try this option:


var contractInstance = MyContract.at('contract_address');
var variable= contractInstance.getName(function(err, res){
    console.log(err); // Error object
    console.log(res); // Result object
    console.log(res.c[0]); // Your "customerName"
});

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.