0

This question already has an answer here:

I have a function in my contract which normally return uint

function insertPerson(
  bytes32 personAddress, 
  bytes32 email, 
  bytes32 fname,
  bytes32 lname) 
  public
  returns(uint index)
{
  if(isPerson(personAddress)) return; 
  persons[personAddress].email     = email;
  persons[personAddress].fname     = fname;
  persons[personAddress].lname     = lname;
  persons[personAddress].index     = personIndex.push(personAddress)-1;
  LogNewPerson(
    personAddress, 
    persons[personAddress].index, 
    email, 
    fname,
    lname);
  return personIndex.length-1;
}

but instead of getting the index i'm getting information about the transaction something like this

{"tx":"0xcfe28fe4cffeb7aa97c2db856920f7a3275d55a656f0550e7f78b76d446970b8","receipt":{"transactionHash":"0xcfe28fe4cffeb7aa97c2db856920f7a3275d55a656f0550e7f78b76d446970b8","transactionIndex":0,"blockHash":"0xcaa35831f7652155de33af8a349e4d5727026d20ec2f280c45d5a8109c8ca1e4","blockNumber":14,"gasUsed":134146,"cumulativeGasUsed":134146,"contractAddress":null,"logs":[{"logIndex":0,"transactionIndex":0,"transactionHash":"0xcfe28fe4cffeb7aa97c2db856920f7a3275d55a656f0550e7f78b76d446970b8","blockHash":"0xcaa35831f7652155de33af8a349e4d5727026d20ec2f280c45d5a8109c8ca1e4","blockNumber":14,"address":"0xf3b5fccbaea5a0bd10542d13c58d808e18aaef9f","data":"0x0000000000000000000000000000000000000000000000000000000000000008646576407369622e636f6d000000000000000000000000000000000000000000646576000000000000000000000000000000000000000000000000000000000061646d696e000000000000000000000000000000000000000000000000000000","topics":["0xa7cb2773240099bbe7a853382f1c2141cd85ac771e1ca8b9c8778fa5a901076e","0x3035343734393837000000000000000000000000000000000000000000000000"],"type":"mined"}],"status":1},"logs":[{"logIndex":0,"transactionIndex":0,"transactionHash":"0xcfe28fe4cffeb7aa97c2db856920f7a3275d55a656f0550e7f78b76d446970b8","blockHash":"0xcaa35831f7652155de33af8a349e4d5727026d20ec2f280c45d5a8109c8ca1e4","blockNumber":14,"address":"0xf3b5fccbaea5a0bd10542d13c58d808e18aaef9f","type":"mined","event":"LogNewPerson","args":{"personAddress":"0x3035343734393837000000000000000000000000000000000000000000000000","index":"8","email":"0x646576407369622e636f6d000000000000000000000000000000000000000000","fname":"0x6465760000000000000000000000000000000000000000000000000000000000","lname":"0x61646d696e000000000000000000000000000000000000000000000000000000"}}]}

can someone help me please, thanks.

marked as duplicate by Ismael, Achala Dissanayake, Richard Horrocks, Roman Frolov, eth Feb 1 '18 at 6:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • How do you invoke this method? – Roman Frolov Jan 26 '18 at 11:05
  • in javascipt like this code contractInstance.insertPerson( web3.fromAscii(String(cin)), email, fname, lname, {gas: 3000000, from: web3.eth.accounts[0]}).then( function(v) { console.log(JSON.stringify(v)); }); – friedman1987 Jan 26 '18 at 11:08
2

It's not very clear how do you invoke your method. But from the response, I assume you're calling it using Web3 or other RPC API.

The idea is that the return values of functions which need to be included into transactions are not returned by Web3.

You have two options:

  1. Using Solidity Events. You should refer to the Events documentation, they're designed to be readable and even "catchable" by the client. Also, check out the Web3 documentation page about working with contract events.

  2. Invoke the function call using Web3 call(). It won't make any changes to your contract state because the method only simulates the "real" call locally without sending any transactions or modifying state, but you will be able to get the function return values.

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