[Ethereum] In ethers.js how to deal wait()

ethers.jsjavascript

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:

.then(function(tx){
wait()=>{}
})

This will not work.

Best Answer

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.

Related Topic