'How to wait for the response in typescript after it sends back an error?
In my Angular project, I am trying to mint a token with a contract address and an abi. Problem is, mint token method takes a lot of time to finish (5 minutes for example) and it returns this error:
Error: Transaction was not mined within 50 blocks, please make sure your transaction was properly sent. Be aware that it might still be mined!
but then it gets mined successfully! even though it threw this error.
Problem is, I want the approve method to happen after the mintToken method is finished successfully, but since it throws this error, the approve method never gets called.
How can I listen to the mintToken method and call approve whenever it finally receives a response?
This is my contract:
this._contract = new this.web3.eth.Contract(MINT_ABI, MINT_CONTRACT);
This is my code:
this._contract.methods
.mintToken(
formValue.wallet,
ipfsLink,
formValue.royaltyRecipient,
royaltyValue
)
.send({ from: formValue.wallet })
.then(
(response: any) => {
console.log(response);
this.createNftService.changeTokenId(response);
this.createNftService.changeWallet(formValue.wallet);
this._contract.methods
.approve(MARKETPLACE_CONTRACT, response)
.send({ from: formValue.wallet })
.then(
() => this.router.navigateByUrl('/create/list'),
(error: any) => {
console.log(error);
}
);
},
(error: any) => {
console.log(error);
}
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
