Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Last active February 19, 2020 01:23
Show Gist options
  • Save alexytiger/2361e9a5b14316253b08228010e8dd45 to your computer and use it in GitHub Desktop.
Save alexytiger/2361e9a5b14316253b08228010e8dd45 to your computer and use it in GitHub Desktop.
e-book
public confirmPurchase(contractAddress: string,
etherValue: string): Observable<string> {
const contract: Contract =
new ethers.Contract(contractAddress, this.abi,
this.provider.getSigner());
const wei = utils.parseEther(etherValue);
const token = contract.buyerPurchase({
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 "LogPurchaseConfirmed"
// call is the last event.
map(txReceipt => txReceipt.events.pop()),
tap(txEvent => console.log('event: ', txEvent.event)),
mapTo(contractAddress),
);
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment