hi i'am student and i start learn ethernaut program for exerce blockchain developpement i have issue
ownerAddr = await contract.owner();
await contract.contributions('0x9CB391dbcD447E645D6Cb55dE6ca23164130D008').then(v => v.toString())
// Output '1000000000000000000000'
this Q2 need to become owner of payable fallback but i don't understant why add .then(v=>v.toString()) ?
v is the result of what is returned by the contributions function which is a promise:
promises
But I wouldn't do it that way:
const result = await contract.contributions('0x9CB391dbcD447E645D6Cb55dE6ca23164130D008')
console.log(result.toString());
in .then()
you collect what the promise gives you back to do something with it. I would mix the traditional way of making promises with your error checking, the .catch(), in this way:
v is the result of what is returned by the contributions function.
But I wouldn't do it that way:
const result = await contract.contributions('0x9CB391dbcD447E645D6Cb55dE6ca23164130D008').catch((error) => {
console.log("Error ", error);
})
console.log(result.toString());
the reserved word await
belongs to another, much more convenient way of managing promises:
async await