In ethers.js,

provider.sendTransaction(rawTransaction).then((transaction) => {
    // A full Transaction Response is returned
    // - from
    // - to
    // - gasLimit, gasPrice
    // - nonce
    // - r, s, v
    // - wait() => Promise that resolves the Transaction Receipt once mined
    //             and rejects with an error is the stats is 0; the error
    //             will have a transactionHash property as well as a
    //             transaction property.

    let hash = transaction.hash;

Here it will return the receipt after wait() how can I write the wait in my code?

I use:


This will not work.

3 Answers 3

const sendTransaction = async() => {
    const transaction = await provider.sendTransaction(rawTransaction);
    // wait() has the logic to return receipt once the transaction is mined
    const receipt = await wait(transaction);

In this way you can write a wait in your code.


For ethers.js v5:

let receipt = await tx.wait()

Either like this:

wait().then(function(receipt) {
    // do whatever you wanna do with `receipt`

Or like this if you call the whole thing from inside an async function:

const receipt = await wait();
// do whatever you wanna do with `receipt`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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