Загрузка...

Функция sleep в код Чекера ETH (нужна помощь)

Тема в разделе Node.js создана пользователем Zaimer433 13 сен 2022. 177 просмотров

  1. Zaimer433
    Zaimer433 Автор темы 13 сен 2022 0 25 июл 2022
    Как притормозить количество запросов в инфури. Сьедает 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()
     
    13 сен 2022 Изменено
  2. pinilopa
    pinilopa 13 сен 2022 Заблокирован(а) 69 17 апр 2021
    Zaimer433, нормально код дай а не этот пиздец
     
  3. Безысходность
    Zaimer433, соглашусь, нормально объясни что ты хочешь
     
  4. Smith
    Smith 13 сен 2022 Beyerdynamic Ambassador 661 29 июл 2022
    Zaimer433, используйте встроенный текстовый редактор[IMG]
    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()
     
  5. LsdDance
    LsdDance 14 сен 2022 722 27 июн 2021
    посмотри в npm sleep
     
  6. mulyar_trx
    mulyar_trx 14 сен 2022 Заблокирован(а) 3 13 июл 2022
    Весь код с циклом помести в отдельную асинхронную функцию,
    ниже пример как юзать
    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();
    Если это решение подходит, лукас пожалуйста новокеку
     
    14 сен 2022 Изменено
Загрузка...
Top