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.

  • Is this full code ? What is the "first method" and "second method" ? Moreover, you have comment section line 2. – Florian Castelain Mar 2 at 7:47
  • approve is my first method and createEscrow is my second method. – Love Chawda Mar 2 at 8:28
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

| improve this answer | |
  • not working only first method execute – Love Chawda Mar 2 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 at 12:01
  • not working only approve call also receipt not logging – Love Chawda Mar 17 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 at 8:34
  • yes now it is working thankyou so much – Love Chawda Mar 17 at 9:10

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.