0

I wanna know how to send the transaction in spesific block numbers with web3js ( Yes its for sniping bot )

The purpose is to avoid the tax in 1-3 blocks since liquidity is added

For example :

New token are going to launch and having an anti sniper by putting those people or bots who are buying in 1-3 blocks from addliquidity transaction with a high tax

Addliquidity is added in 11008801 and the block on 11008801-11008803 having a high tax

how can i skip those blocks and send my transaction at 11008804 blocks ?

Someone told me to just add a delay with second , but im afraid that huge project launch will messing the second ( is it ? )

because from what i know is 1 block = 3 second and yeah im afraid if i put the delay by second for example im guessing that 3 second is 1 block but if the token are hyped and lot of transaction into it , maybe it will messing the second like 3 second become 10 block or more

sorry for my bad english , and thank you.

3 Answers 3

0

if it is for basic dApp requirement, you can use web3.eth.getBlockNumber(). Please let me share an example code snippet available on GitHub from a recently updated repository.

getPastLockboxSoldEvents: async function (pastBlockCount) {
            if (this.contract) {
                let events = await this.contract.getPastEvents('LockboxSold', {
                    fromBlock: await web3.eth.getBlockNumber() - pastBlockCount,
                    toBlock: 'latest'
                });

                for (let i = 0; i < events.length; i++) {
                    let event = events[i];

                    event.transactionDate = new Date((await web3.eth.getBlock(event.blockNumber)).timestamp * 1000);

                    event.returnValues.id = event.returnValues.id.substring(0, 34);
                    event.returnValues.price = parseFloat(web3.utils.fromWei(event.returnValues.price));
                }

                return events;
            }
0

To send a transaction at a specific block (like 11008804) and skip the high-tax blocks (11008801 to 11008803), you should avoid relying on time-based delays. The reason is that block times on Ethereum can vary depending on network activity. For example, during a hyped token launch, blocks might be mined faster or slower than the usual average of 3 seconds, making time delays unreliable.

Instead, you can monitor the blockchain to wait for the exact block number and then send your transaction.

Use the web3.eth.subscribe('newBlockHeaders') function to listen for new blocks in real time.you can check further about this here! Continuously compare the current block number to your target block (11008804). Once the current block matches or exceeds your target, send your transaction immediately..

-2

There is no way to determine in which block your transaction is mined.

The transaction order depends on the miner configuration, transaction nonce, etc. Nothing that you can determine in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.