How to fund a account with ETH on a local fork or local node in hardhat?

Expert

Let's say I have an account in hardhat ```javascript [owner, user, user2] = await ethers.getSigners(); userAddress = user.address; ``` How would I fund `userAddress` with funds on my local fork?

Answers 2

Whenever Hardhat spins up a local instance, it creates pre-funded accounts. You can access those accounts if import *ethers* from *hardhat*. ``` const { ethers } = require("hardhat"); async function main() { const accounts = await ethers.getSigners(); const provider = ethers.provider; for (const account of accounts) { console.log("%s (%i ETH)", account.address, ethers.utils.formatEther( await provider.getBalance(account.address) ) ); } } main() .then(() => process.exit(0)) .catch(error => { console.error(error); process.exit(1); }); ```

You can use `setBalance` from the [hardhat docs](https://hardhat.org/hardhat-network/docs/reference#hardhat_setbalance) ```javascript await network.provider.send("hardhat_setBalance", [ userAddress, "0x1000000000000000000000000", // we are giving ourselves a LOT eth ]); // then we can print out how much we have in hex console.log( await network.provider.send("eth_getBalance", [ impersonatedSigner.address, ]) ); ```