Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
Web3.js Script exits while listening to CreatedPairs

I am trying to create a simple script to test the event listening functionality of Web3.js CreatedPairs. However, my script runs through the code once and then exits instead of continuing to listen for created pairs and I cannot figure out why.

const Web3 = require('web3')
const web3 = new Web3(Web3.givenProvider || 'https://mynodeishere');

const IUniswapV2Factory = require("@uniswap/v2-core/build/IUniswapV2Factory.json")
const UNI_FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'
const uFactory = new web3.eth.Contract(IUniswapV2Factory.abi, UNI_FACTORY_ADDRESS)


const main = async () => {

    // Create event listener to listen to PairCreated
    uFactory.events.PairCreated({}, async (error, event) => {
    
        console.log(`New pair detected...\n`)

    })
}

main()

What ends up happening is when I run node ./myapp.js. The code gets stepped in to and logs New pair detected... to the console and then exits. This happening right away tells me that it is not executing when a new pair is detected and is instead just stepping through the code.

However, what I anticipated happening, was for the app to continue to run and log to the console only when a new pair is detected. I am sure I am overlooking something small, but any help would be appreciated.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

In this context, Web3.givenProvider is null, so the HTTP provider is used.

To be able to subscribe to events, you need to use a WSS provider.

// example connection to a WSS provider
const web3 = new Web3('wss://mainnet.infura.io/ws/v3/<yourtoken>');
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda