forked from CodeWithJoe2020/sendNativeandERC20TokenEthersJs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendNative.js
More file actions
34 lines (22 loc) · 714 Bytes
/
sendNative.js
File metadata and controls
34 lines (22 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// transfer Native Balance
const {ethers} = require('ethers')
const node = 'Quicknode https://bit.ly/3QxPwWk'
const provider = new ethers.providers.JsonRpcProvider(node)
const privatekey = 'sender Privatekey'
const wallet = new ethers.Wallet(privatekey, provider)
const receiver= 'receiver tokenAddress'
const sender = 'sender tokenAddress'
const amountToSend = '0.00045'
const tx ={
to: receiver,
value: ethers.utils.parseEther(amountToSend)
}
async function main(){
const balance = await provider.getBalance(sender)
console.log(ethers.utils.formatEther(balance))
wallet.sendTransaction(tx)
.then((txObj) => {
console.log('txHash', txObj.hash)
})
}
main()