2023-03-30 13:21:11 +00:00
|
|
|
import { task } from 'hardhat/config'
|
|
|
|
import '@nomiclabs/hardhat-ethers'
|
|
|
|
|
|
|
|
task('send-balance', 'Sends Ether to a specified Ethereum account')
|
|
|
|
.addParam('to', 'The Ethereum address to send Ether to')
|
|
|
|
.addParam('amount', 'The amount of Ether to send, in Ether')
|
|
|
|
.addParam('privateKey', 'The private key of the sender')
|
|
|
|
.setAction(async ({ to, amount, privateKey }, { ethers }) => {
|
|
|
|
// Open the wallet using sender's private key
|
|
|
|
const wallet = new ethers.Wallet(privateKey, ethers.provider)
|
|
|
|
|
|
|
|
// Send amount to the specified address
|
|
|
|
const tx = await wallet.sendTransaction({
|
2023-03-30 13:37:01 +00:00
|
|
|
to,
|
2023-03-30 13:21:11 +00:00
|
|
|
value: ethers.utils.parseEther(amount),
|
|
|
|
})
|
|
|
|
|
2023-03-30 13:37:01 +00:00
|
|
|
console.log(`Balance sent to: ${to}, from: ${wallet.address}`)
|
2023-03-30 13:21:11 +00:00
|
|
|
console.log(`Transaction hash: ${tx.hash}`)
|
|
|
|
})
|