0

i want to call two methods first call one method then second method after first method success below is my code please check and let me know how i can achieve this

this.state.token.methods.approve(this.state.neutralG.address, qty).send({ from: this.state.account}).
  then('receipt', (receipt)=>{

   this.state.neutralG.methods.createEscrow(intvalue, 3600, price, this.symbol, beneficiaryAddress, qty,
    this.tokenAddress).send({ from: this.state.account}).
  once('receipt', (receipt)=>{
    this.setState({loading: false})
  })

  })

this is not calling second transaction.

2
  • Is this full code ? What is the "first method" and "second method" ? Moreover, you have comment section line 2. Mar 2, 2020 at 7:47
  • approve is my first method and createEscrow is my second method. Mar 2, 2020 at 8:28

1 Answer 1

1

Your on, once and then are wrong. Please try as below:

this.state.token.methods.approve(this.state.neutralG.address, qty).send({ from: this.state.account})
  .on('receipt', (receipt)=>{
this.callCreateEscrow();
console.log('receipt');
  })

function callCreateEscrow(){
this.state.neutralG.methods.createEscrow(intvalue, 3600, price, this.symbol, beneficiaryAddress, qty,
    this.tokenAddress).send({ from: this.state.account})
  .on('receipt', (receipt)=>{
    this.setState({loading: false})
  })
}

And also please check other things in .on('<>', ).... They can be 'receipt', 'confirmation', 'transactionHash' etc.,

reference: https://web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html#id22

4
  • not working only first method execute Mar 2, 2020 at 9:14
  • I have edited my answer. Can you check and tell if this works. And also check if receipt is getting logged.
    – vteja711
    Mar 3, 2020 at 12:01
  • not working only approve call also receipt not logging Mar 17, 2020 at 6:17
  • Then your approve is not returning any receipt. Can you try using 'transactionHash' instead of 'receipt' and check if it is getting a Hash or not
    – vteja711
    Mar 17, 2020 at 8:34

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.