How to return result as variable from provider.on? #2018
Answered
by
zemse
adityawarmanfw
asked this question in
Q&A
-
Hi, I want to listen to pending transactions using provider.on, and it works with this code:
Now I want to pass the result from the provider.on to a variable, but I can't figure out how to do that. Here's the function I wrote:
I don't really get why this isn't working. Can somebody help? Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
zemse
Sep 9, 2021
Replies: 1 comment 3 replies
-
You may use a Promise; const streamPendingTx = (connect) => {
return new Promise(resolve => {
connect.provider.on("pending", (pendingHash) => {
resolve(pendingHash);
})
})
};
(async () => {
const result = await streamPendingTx(connectWSS())
console.log(result);
})() |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
adityawarmanfw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may use a Promise;