2

I'm trying to send ETH in goerli by this code

let

 provider = ethers.getDefaultProvider(process.env.ETHEREUM_NETWORK);
let wallet = new ethers.Wallet(prK, provider);
wallet.sendTransaction({
  to: process.env.ADMIN_WALLET_ADDR_ON_ETHEREUM,
  value: ethers.utils.parseEther("0.0001")
})
.then((x) => {
  console.log(`OK: ${x}`)
});

While it'll send ETH successfully, and it'll appear on etherscan, it'll never get to the console.log(...) part. That is, it'll stop and hang in the terminal indefinitely until I break it by Ctrl + C.

What's the matter? How to fix it?

2 Answers 2

0

I don't understand what you exactly need to log, but maybe you can try assigning the transaction to a variable, use await and display it after. Something like:

provider = ethers.getDefaultProvider(process.env.ETHEREUM_NETWORK);
let wallet = new ethers.Wallet(prK, provider);

async function main () {
    let result = await wallet.sendTransaction({
        to: process.env.ADMIN_WALLET_ADDR_ON_ETHEREUM,
    console.log(result)
    })
}

main()
0
0

At first sight, I Would say that this behavior (not executing the console.log) is due to you not handling errors with catch, try to add a catch statement and to console.log().

For the indefinite wait, it looks like a promise not resolving, meaning that it's in the indefinite state of pending, it is likely to be due again to the absence of catch statement : errors not being resolved.

I might be wrong on this one, feel free to correct me if you find the answer.

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.