Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public confirmPurchase(contractAddress: string, etherValue: string): Observable<string> {
- // Connect to the Contract using a Provider
- const contract: Contract = new ethers.Contract(contractAddress, this.abi, this.provider.getSigner());
- const wei = utils.parseEther(etherValue);
- // Call the contract method, getting back the transaction tx
- const token = contract.buyerConfirmPurchase({
- value: wei
- });
- return from(token)
- .pipe(
- switchMap((tx: any) => {
- console.log('buyerConfirmPurchase Tx:', tx);
- // Wait for transaction to be mined
- // Returned a Promise which would resolve to the TransactionReceipt once it is mined.
- return from(tx.wait()).pipe(
- tap((txReceipt: any) => console.log('txReceipt: ', txReceipt)),
- // The receipt will have an "events" Array, which will have
- // the emitted event from the Contract. The "PurchaseConfirmed"
- // call is the last event.
- map(txReceipt => txReceipt.events.pop()),
- tap(txEvent => console.log('event: ', txEvent.event)),
- mapTo(contractAddress),
- )
- }))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement