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

202
Vistas
How to provide credentials to Ankr when calling the API with Web3.js HttpProvider?

I am trying to get access to Ankr API address, which is like:

https://apis.ankr.com/XXXX/YYYY/full/main

When accessing this link by the browser I can introduce the credentials I created on Ankr panel control and I can pass successfully. However now I am trying to do this with Web3.js on Node:

var options = {
    headers: [
        {
            name: 'Authorization',
            value: 'Basic myUsername:myPassword',
        },],};

const web3 = new Web3(new Web3.providers.HttpProvider('https://apis.ankr.com/XXXX/YYYY/full/main', options))

And I receive a 401 Unauthorized error response. I assume that my credentials are right because I could access them by the link on the browser, but not when passing in the header they seem not work. What is wrong in the code or what lacking of?

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

0

You need to pass the base64 of the myUsername:myPassword, not the actual plaintext.

// base64 encoded
value: 'Basic ' + Buffer.from('myUsername:myPassword').toString('base64'),

See the MDN docs for more info.

over 4 years ago · Santiago Trujillo Denunciar

0

The problem is that the credentials had to be hashed somehow.

I do not know if this is the most suitable solution, but I finally solved this by visiting the address on my browser (https://apis.ankr.com/XXXX/YYYY/full/main), opened dev tools on Chrome, and log in introducing my credentials.

Then I got the hashed credential sent on the request by checking the HEADER of my request (on Chrome, this is done in Network>therequest>Request Headers>authorization). I just copy/pasted this hashed credential on the js code and it worked!

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