Is it possible to schedule a transaction to execute after a certain amount of time in ethereum? For example, I have a reservations dapp.The customer makes a reservation and a transaction is sent to the Booking smart contract. When the stay ends (end date), I want to call, automatically, a getRefund method function on the Booking smart contract, but I don’t want the user to manually execute the request. If it is possible how can i do it in web3.js?
A transaction needs to be externally initiated. You could write a script to check if there are any refunds and if there are create a transaction to refund. You could then create infrastructure to run this periodically e.g. every 5 minutes.
You could use OpenZeppelin Defender Autotasks to handle running a script periodically.
I suggest joining the weekly webinar to learn more: Webinar: Introduction to OpenZeppelin Defender - Wednesday 10 February 2021
You had asked about gasless transactions so you may be interested in the workshop too: Workshop: Gasless MetaTransactions with OpenZeppelin Defender - Thursday 11 February 2021
@abcoathup Is it possible to use web3.js instead of ethers.js? I can’t find any examples or tutorials with web3.js
Another question is: I have a start date and an end date. I want to have my script call a smart contract function every day, but the first call must also be made by the script and not by the user. Is it possible with Defender Autotasks?
For your own script you can use
ethers.js. For Defender the support is currently just for
You could have an Autotask running every few minutes, checking if it needs to do anything and then creating a transaction.
Alternatively, you could use a webhook to trigger an Autotask when a customer does something in your app.