Lesson 8 - JS Syntax Question #2384
-
Prior to this course, I had not written JS for a very long time, and now I'm still struggling with the some of the syntax. What breaks my brain is when a function takes a function as an argument which itself takes a parameter . So for example provider.once(transactionResponse.hash, (transactionReceipt) => {
console.log(
`Completed with ${transactionReceipt.confirmations} confirmations`
)
}) I understand that the once() function takes an event, and a listener function. But where does transactionReceipt come from? How do we get that to pass into our listener function? Can somebody please explain the above code in plain English? I am not sure whether to carry on with this course or take a break and learn some more JS. I've managed to get everything working so far, but there are quite a few bits of code that remain a mystery to me! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@alkali333 The second parameter (function) is the result of the first parameter. provider.once(transactionResponse.hash, (transactionReceipt) => {
console.log(
`Completed with ${transactionReceipt.confirmations} confirmations`
)
}) Here we are saying to provider to listen to this response hash |
Beta Was this translation helpful? Give feedback.
-
@alkali333 Let me see if I can give you the best explanation possible here. Imagine we want to create a function that creates a user account and then sends the user an email welcoming them to the platform. In this case, we can approach it in 2 ways,
So to use such a function, we would use it this way;
|
Beta Was this translation helpful? Give feedback.
@alkali333 The second parameter (function) is the result of the first parameter.
Here we are saying to provider to listen to this response hash
transactionResponse.hash
andonce
it gets called pass the result of it here(transactionReceipt)
. And the second parameter is callback where we explore our result further