1

What is the best way to handled nested contract call with web3 1.0? I'm trying to collect all data needed and format it into something useable. It could require 2 or 3 calls though. Is there a easy way to handle it, to know when all async calls have finished?

this.contract.methods.getPlayerAnimals(this.address)
.call({ from: this.address })
.then((animals) => {
  for (var animal of animals) {
    this.contract.methods.getAnimal(animal)
    .call({ from: this.address })
    .then((animalContract) => {
      this.playerAnimals.push(fullAnimal)
    });
  }
  this.socket.emit('playerAnimals', this.playerAnimals)
});
0
var animals = await this.contract.methods.getPlayerAnimals(this.address)
  .call({ from: this.address })
for (var animal of animals) {
  var animalContract = await this.contract.methods.getAnimal(animal)
    .call({ from: this.address })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.