Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public confirmPurchase(contractAddress: string, etherValue: string): Observable<string> {
  2.  
  3. // Connect to the Contract using a Provider
  4. const contract: Contract = new ethers.Contract(contractAddress, this.abi, this.provider.getSigner());
  5.  
  6. const wei = utils.parseEther(etherValue);
  7.  
  8. // Call the contract method, getting back the transaction tx
  9. const token = contract.buyerConfirmPurchase({
  10. value: wei
  11. });
  12.  
  13. return from(token)
  14. .pipe(
  15. switchMap((tx: any) => {
  16.  
  17. console.log('buyerConfirmPurchase Tx:', tx);
  18. // Wait for transaction to be mined
  19. // Returned a Promise which would resolve to the TransactionReceipt once it is mined.
  20. return from(tx.wait()).pipe(
  21. tap((txReceipt: any) => console.log('txReceipt: ', txReceipt)),
  22.  
  23. // The receipt will have an "events" Array, which will have
  24. // the emitted event from the Contract. The "PurchaseConfirmed"
  25. // call is the last event.
  26. map(txReceipt => txReceipt.events.pop()),
  27. tap(txEvent => console.log('event: ', txEvent.event)),
  28. mapTo(contractAddress),
  29. )
  30. }))
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement