0

Here is my code Sample in js script connected to ContractInstance through web3:

ContractInstance.Fire(function(error,res){
   if(!error){ContractInstance.dead.call(function(err, result){
              console.log(result);});}
             });

ContractInstance.dead.call(function(err, result){
                  console.log(result) });
  • So when I call fire function of contract then my dead variable changes to true (I confirm it in remix )
  • And then I call dead variable inside Fire function.
  • Somehow it prints false in the console, but later when I call it outside the function it prints true.

I don't know why this is happening maybe because

  • when I call fire function it stops for a while because metamask asks for confirmation .

  • or it might be due to the fact that it does not update in the contract so quickly.

Can somebody help me how should I call dead variable just after the the fire function is called ?

1 Answer 1

1

The first callback from .Fire returns a transaction receipt. This is very minimal information that indicates that your node is aware of the transaction. Think "ack."

The next step is to wait for the transaction to be mined. Basically, wait for a block to arrive that includes the TxHash you got from the first callback.

The effect of the transaction is not apparent until after it's mined. That's why you're getting results on the console (immediately) that differ from what you see (later) when you check it yourself.

Have a look at this handy tool: https://gist.github.com/xavierlepretre/88682e871f4ad07be4534ae560692ee6

Hope it helps.

1
  • Oh I see.. thank you for that knowledge. So for the solution sake I shall make an event named dead in my contract, I think that will do? Commented Oct 21, 2018 at 10:03

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.