Как притормозить количество запросов в инфури. Сьедает 100000 запросов в течении 10 минут. Как функцию sleep организовать? Вот код чекер баланса ETH. Через API infury. Куда прописать и как slepp???? constructor(projectId, account) { this.web3 = new Web3(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws/v3/...............')); this.account = account.toLowerCase(); } subscribe(topic) { this.subscription = this.web3.eth.subscribe(topic, (err, res) => { if (err) console.error(err); }); } watchTransactions() { console.log('Watching all pending transactions...'); this.subscription.on('data', async (txHash) => { try { const tx = await this.web3.eth.getTransaction(txHash); if (tx && tx.to && this.account == tx.to.toLowerCase()) { console.log({ address: tx.from, value: this.web3.utils.fromWei(tx.value, 'ether'), gasPrice: tx.gasPrice, gas: tx.gas, input: tx.input, timestamp: new Date()
Zaimer433, используйте встроенный текстовый редактор constructor(projectId, account) { this.web3 = new Web3(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws/v3/...............')); this.account = account.toLowerCase(); } subscribe(topic) { this.subscription = this.web3.eth.subscribe(topic, (err, res) => { if (err) console.error(err); }); } watchTransactions() { console.log('Watching all pending transactions...'); this.subscription.on('data', async (txHash) => { try { const tx = await this.web3.eth.getTransaction(txHash); if (tx && tx.to && this.account == tx.to.toLowerCase()) { console.log({ address: tx.from, value: this.web3.utils.fromWei(tx.value, 'ether'), gasPrice: tx.gasPrice, gas: tx.gas, input: tx.input, timestamp: new Date() JavaScript constructor(projectId, account) { this.web3 = new Web3(new Web3.providers.WebsocketProvider('wss://mainnet.infura.io/ws/v3/...............')); this.account = account.toLowerCase(); } subscribe(topic) { this.subscription = this.web3.eth.subscribe(topic, (err, res) => { if (err) console.error(err); }); } watchTransactions() { console.log('Watching all pending transactions...'); this.subscription.on('data', async (txHash) => { try { const tx = await this.web3.eth.getTransaction(txHash); if (tx && tx.to && this.account == tx.to.toLowerCase()) { console.log({ address: tx.from, value: this.web3.utils.fromWei(tx.value, 'ether'), gasPrice: tx.gasPrice, gas: tx.gas, input: tx.input, timestamp: new Date()
Весь код с циклом помести в отдельную асинхронную функцию, ниже пример как юзать function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } // Чтобы юзать эту функцию родительская должа быть async // Пример: async function foo(obj){ for(key in obj){ let e = obj[key]; console.log(e); await sleep(500); // } } foo(); JavaScript function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } // Чтобы юзать эту функцию родительская должа быть async // Пример: async function foo(obj){ for(key in obj){ let e = obj[key]; console.log(e); await sleep(500); // } } foo(); Если это решение подходит, лукас пожалуйста новокеку