'Passing eventlisteners in promisses
Code process:
- Transaction is created with completeorders() function.
- Created transaction event listener activates and logs to console.
- Once the created transaction event listener activates, the confirmed transaction or failed transaction event will be waiting to be completed.
- once either the confirmed transaction or failed transaction event occurs, the script stops running.
I am having issues with creating the promise to wait for the transaction confirmation or transaction failed once the created transaction event is triggered. Here is my attempt at this process so far:
async function logging() {
seaport.addListener(openseajs.EventType.TransactionCreated, ({ transactionHash, event }) => {
console.log(`Transaction Created : ${transactionHash} Waiting for confirmation`);
return await new Promise(function(resolve){
seaport.addListener(openseajs.EventType.TransactionConfirmed, ({ transactionHash, event }) => {
console.log(`Transaction Confirmed : ${transactionHash}`);
resolve();
}) ||
seaport.addListener(openseajs.EventType.TransactionFailed, ({ transactionHash, event }) => {
console.log(`Transaction Failed : ${transactionHash}`)});
resolve();
})
})
console.log("listening...")
};
async function main() {
await function1();
await function2();
await completeorders();
}
setInterval(main,5000);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|