-
There are many instances in ethers.js that create immediately resolved promise and await on it. For example,
const hexTx = await Promise.resolve(signedTransaction).then(t => hexlify(t));
tx[key] = Promise.resolve(values[key]).then((v) => (v ? this._getAddress(v): null)); Why not const hexTx = hexlify(signedTransaction);
tx[key] = Promise.resolve(values[key] ? this._getAddress(values[key]): null); Because this pattern is used intensively, I suppose they were done on purpose. But I could not find a something clear. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Most methods (especially in the provider, where things are already wildly async) take in either a But for example, in your above example for the second case, Make sense? |
Beta Was this translation helpful? Give feedback.
Most methods (especially in the provider, where things are already wildly async) take in either a
Promise<string> | string
. By passing it throughPromise.resolve
, the logic is greatly simplified. This may be changing in v6, still contemplating about it, sinceawait
is now fairly widespread. :)But for example, in your above example for the second case,
hexlify(signedTransaction)
would result in an error if aPromise<string>
was passed in forsignedTransaction
.Make sense?