I am facing issue with when I use this template code as trigger to one of the monitoring event on a smart contract I want the code to execute but only after a certain time delay which needs to be randomly choosen btween 6-8 minutes. So I use a one lineer code from ai generated like this one
setTimeout(() => console.log("Waited for a random duration"), Math.floor(Math.random() * 240000) + 360000);
but when i put this one liner code at the start of the action javascript code and run it the code executes without considering this time delay right away, can you help me how can i implement this random time delay before the sending of the transaction in action code. Is there any alternative to asyn function or another workaround so that i can have this time delay before actually sending the transaction. Thanks team
The time in milliseconds to wait before the specified function is executed
In your code, the value of the 1st input argument is:
() => console.log("Waited for a random duration")
This is a function which takes no input, prints a message, and returns no output.
The code in THIS function is THE ONLY part in your program which is subjected to the requested timeout; anything appearing after your call to the setTimeout function, will continue running IMMEDIATELY after that call, without being subjected to any timeout.
Thanks Barakman but I am bit novice to js and openzeppelin all i know is that this function is not doing what i intend it to do can you please correct it so that It does function as per my requirment or if not update it with a better code which can perform the function as per what i need, Thanks.
I don't have a subscription to OpenZeppelin's Defender (nor do I wish to pay for it)
I obviously cannot execute your transaction (nor do I wish to pay for it)
I have no idea what the credentials are
I have no idea what the contract i am monitoring is
I have no idea what the function method id i am calling is
I don't see userHandler anywhere in your code, so I cannot say where that error stems from
Finally, regarding:
I think that you need to learn some basic concepts, BOTH in JavaScript AND in OpenZeppelin, before moving forward with this project (i.e., instead of just "throwing in a piece of code" and hoping that it would miraculously "do what you intend it to do" somehow).
I can help with a specific technical problem, but I'd require all the relevant technical details, and most of them are completely absent in your question.