2

I'm sending a transaction to a contract from Javascript through web3. The transaction is created. The solidity function is (partially) executed because it sends the token it's expected to send... but, values are no stored in a mapping.

I tested with browser-solidity and it works. I tested with https://www.myetherwallet.com and it works. In both cases, I can retrieve the values of the mapping. But when I do through javascript, it doesn't work.

Here is the code of javascript calling function:

  scheduleAppointment : function(_patient, _doctor, _appointmentDateTime) {
    var patientAddress      = document.getElementById("patientInput");
    var doctorAddress       = document.getElementById("doctorInput");
    var appointmentDateTime = document.getElementById("timeStampInput");
    contractInstance.scheduleAppointment.sendTransaction(patientAddress.value,
                                                         doctorAddress.value,
                                                         appointmentDateTime.value,
                                                         {gas:140000, from:web3.eth.accounts[0]});
  }

Here is the code of solidity function (this function does not send tokens, only stores to mapping):

function scheduleAppointment(address _patient, address _doctor, uint _appointmentDateTime) {
    appointmentsList[_patient][_doctor][_appointmentDateTime].appointmentStatus    = 1;
}

As you see, it would be impossible to make it more simple.. but it doesn't work. Transaction is created, but the value is not stored in the mapping.

Should I convert parameters before sending them from javascript? I couldn't find any reference for sending many parameters with sendTransaction. I've tried converting the integer value with parseInt when calling the function with javascript, but it's the same.

Any ideas? Thanks.

1 Answer 1

1

I'm sorry, the functions worked properly. The problem was that they run out of gas... I can remove the question if you consider that it does not add anything useful.

1
  • It can be helpful to others, missing the correct gas value is a pretty common issue.
    – Ismael
    Commented Oct 19, 2017 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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