Загрузка...

sleep function in ETH checker code (need help)

Thread in Node.js created by Zaimer433 Sep 13, 2022. 178 views

  1. Zaimer433
    Zaimer433 Topic starter Sep 13, 2022 0 Jul 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()
     
  2. pinilopa
    pinilopa Sep 13, 2022 Banned 69 Apr 17, 2021
    Zaimer433, нормально код дай а не этот пиздец
     
  3. Безысходность
    Zaimer433, соглашусь, нормально объясни что ты хочешь
     
  4. Smith
    Smith Sep 13, 2022 Beyerdynamic Ambassador 661 Jul 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 Sep 14, 2022 722 Jun 27, 2021
    посмотри в npm sleep
     
  6. mulyar_trx
    mulyar_trx Sep 14, 2022 Banned 3 Jul 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();
    Если это решение подходит, лукас пожалуйста новокеку
     
Loading...
Top