Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Created September 29, 2019 20:35
Show Gist options
  • Save alexytiger/b2a0531e7a3178af0616ce312c849944 to your computer and use it in GitHub Desktop.
Save alexytiger/b2a0531e7a3178af0616ce312c849944 to your computer and use it in GitHub Desktop.
public confirmDelivery(contractAddress: string): Observable<string> {
// We connect to the Contract using a Provider
const contract: Contract = new ethers.Contract(contractAddress, this.abi, this.provider.getSigner());
// Call the contract method, getting back the transaction tx
const token = contract.buyerConfirmReceived();
return from(token)
.pipe(
switchMap((tx: any) => {
console.log('buyerConfirmReceived 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 "ItemReceived" from the contract
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