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

142
Vistas
How to update a web3 provider in reactjs application?

I have a reactjs application using web3 where I have a provider set in a context via Web3ReactProvider

<Web3ReactProvider getLibrary={getLibrary}>
 <MyCoolApplication />
</Web3ReactProvider>

my users also can switch between the networks, so I'd like to update web3's provider based on a user's choice

so this is what I am doing to have such a functionality:

const getLibrary = useCallback(() => {
 let provider = ''

 switch (web3Provider.selectedProvider) {
  case 'network1':
    provider = Web3.givenProvider
    break
  case 'network2':
    provider = 'bla-bla-bla-1'
    break
  case 'network3':
    provider = 'bla-bla-bla-3'
    break
  default:
    provider = Web3.givenProvider
    break
 }

 return new Web3(provider)
}, [web3Provider])

looks like it has to work properly, but when I am trying to get any token's data via web3React.library.eth.Contract... and etc

there is nothing responded at all :(

so the question is whether I can update a provider like that or should I do anything else?

Thank you

about 4 years ago · Juan Pablo Isaza
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