'How to send TX in the same block with emitted event in ethers.js
I am listening to a specific contract on the blockchain and when a certain event occurs on the contract, I send a TX. In the best case my TX is mined in the next block of the specific event that I am using as my trigger.
In blockchain explorer I see some addresses whose TX's are mined in the exact same block as their trigger events.
My question is how can I send a TX to be mined in the same block as the emitted contract event that I am using as my trigger?
I am currently using ethers.js as follows
filter = {address: "0x...."} // Contract address that I am listening to
// Start listening
provider.on(filter, async (_event) => {
// Do something with _event when a TX is emitted
// Sign a raw TX if certain criteria is met
await send_tx(tx_data, gasPrice, gasLimit)
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
