0

I'm early in learning solidity (that's probably obvious). No idea why I'm getting this result.

medsToBeDeveloped has a length of 0 at begining

 uint [] medsToBeDeveloped;

 function returnProductID() external returns(uint){
    uint randNum = medsToBeDeveloped.length;
    medsToBeDeveloped.push(randNum);
    potentialMedsToManufacturer[randNum] = msg.sender;
    return(randNum);
}

Javascript:

$("#requestID").on('click', function(){
announceButton("request ID");
contract.returnProductID(function(err, id){
  console.log(typeof id);
  console.log("id: " + parseInt(id) + " thatis all");
  });
})

I'm probably doing something very obvious

  • What is the question? – valem Feb 25 at 2:31
1

I think you're getting a transaction hash and mistaking it for an address.

This function changes the state and therefore results in a transaction sent to the network for verification. You would have to wait for the transaction to be mined and then access a view function to see the result.

The first async response is the transaction hash that you can use to await confirmation. Monitoring that transaction for confirmations is a separate client-side concern.

This admittedly brief explanation will raise some new questions, like how to wait for it to be mined. This might help: What's the proper way to wait for a transaction to be mined and get the results?

And what is a view function? https://blog.b9lab.com/calls-vs-transactions-in-ethereum-smart-contracts-62d6b17d0bc2

Hope it helps.

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.