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

152
Vistas
.then() function never running for call to blockchain

Please find below my code snippet. Here credentialHash is not being set in the .then() call. Neither the "In then" or "Callback rejected" are being printed so I know that it is not running but I cant understand why. I've also included code for the setHash function in my smart contract.

let hash;
    await ipfs.add(JSON.stringify(this.state.credential)).then((result, error) => {
      hash = result.path;
      if (error) {
        console.error(error)
        return;
      }
      // Store hash on blockchain
      console.log("Hash before BC:" + hash);
      this.state.contract.methods.setHash(hash).send({from: this.state.account}).then((resolve) => {
    console.log("In then")
    this.setState({credentialHash: hash});
  }, (rejected) => {
    console.log("Callback rejected");
  });
      console.log("After setting:" + this.state.credentialHash);
    });

function setHash(string memory _CredentialHash) public returns(string memory) { credentialHash = _CredentialHash; return _CredentialHash; }

The result returned from console.log(this.state.contract.methods.setHash(hash).send({from: this.state.account})) is :

Proxy {promise: Promise, eventEmitter: EventEmitter, resolve: ƒ, reject: ƒ}
[[Handler]]: Object
get: ƒ proxyHandler(target, name)
[[Prototype]]: Object
[[Target]]: PromiEvent
eventEmitter: EventEmitter
_events: Events
[[Prototype]]: Object
_eventsCount: 0
[[Prototype]]: Object
promise: Promise
[[Prototype]]: Promise
[[PromiseState]]: "pending"
[[PromiseResult]]: undefined
reject: ƒ ()
resolve: ƒ ()
[[Prototype]]: Object
[[IsRevoked]]: false
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try dropping the .then() syntax entirely and use only the async/await style. What does the code below give?

let hash, result;

try {
  result = await ipfs.add(JSON.stringify(this.state.credential))
  hash = result.path;
} catch (error) {
  console.error(error)
  return;
}

// Store hash on blockchain
console.log("Hash before BC:" + hash);

try {
  await this.state.contract.methods.setHash(hash).send({
    from: this.state.account
  })
} catch(error) {
  console.log("Callback rejected");
  return
}

this.setState({
  credentialHash: hash
});

console.log("After setting:" + this.state.credentialHash);
about 4 years ago · Juan Pablo Isaza Denunciar

0

For anyone else with this issue, I finally found the answer. The default number of transactionConfirmationBlocks is 24 which takes a long time to complete. Setting this to 1 as below solved my issue.

this.setState({contract: new web3.eth.Contract(
      credentialArtifact.abi,
      deployedNetworkCred.address,
        {transactionConfirmationBlocks: 1}
  )});
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