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

244
Vistas
How to properly format bytes32 in javascript to send to contract?

I am trying to use the keccak256 function to recover a signed address (basically implementing a whitelisting functionaltiy for an NFT project).

The problem that I am having is that I can not figure out what the proper format of bytes32 for the hash is.

Here is what I am doing so far:

const signerPrivateKey = "someprivatekey"
const signer = new ethers.Wallet(signerPrivateKey);
const hashedAddress = ethers.utils.id(potentialWhiteListAddress);
const hashedAddressBytes = ethers.utils.arrayify(hashedAddress);
const signedAddress = await signer.signMessage(hashedAddressBytes);

return { signedAddress, hashedAddress };

Then when interacting with my contract, the function that I am trying to use is:

function recoverSigner(bytes32 hash, bytes memory signature) public pure returns (address) {
  bytes32 messageDigest = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));

  return ECDSA.recover(messageDigest, signature);
}

Calling the contract function from the frontend:

// hashedAddress - 0xdb2ec52069cba65d62a560cad9088e7a709d09e7c14b33d740bXXXXXXXXXXXXX
// signedAddress - 0xd49bc3982f08cb0d67d7a070ffee33b348ab28c70f98bbc67a8fc89e8b419a5865007411d0c2131636dc4e6779a0d88f631c5edf5a75a806853d06b8XXXXXXXXXX

await myContract.recoverSigner(hashedAddress, signedAddress);

However, I keep getting the error, because (im assuming) hashedAddress is actually 64bytes (64 characters):

Error: bytes32 string must be less than 32 bytes
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I found the problem, I was doing the signing on the backend with an api call and returning the hashed bytes array as a response, apparently for some reason nextjs is turning numeric array into an object, so I ahd to turn it back into a simple numeric array.

const hashedAddressBytesArray = Object.keys(
        data.hashedAddressBytes
      ).map((key) => data.hashedAddressBytes[key]);
about 4 years ago · Juan Pablo Isaza 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