-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckBalance.ts
36 lines (28 loc) · 1.04 KB
/
CheckBalance.ts
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
35
36
import Web3 from "web3";
import * as dotenv from 'dotenv';
//const walletAddress ="0xda67DE242bE3582EfE6b5713068BD9bA2f621A0E";
//const rpcURL = "https://rinkeby.infura.io/v3/0f198830abf541cc940d522d1ccb8876";
dotenv.config();
//console.log(process.env);
export const chkBalance = async():Promise<any>=>{
try {
const web3 = new Web3(new Web3.providers.HttpProvider(process.env.rpcRinkebyURL));
const balance = await web3.eth.getBalance(process.env.walletAddress);
console.log('Your balance is:', web3.utils.fromWei(balance,'ether'));
} catch (error) {
console.log("Error: ", error);
}
}
chkBalance().catch((error) => {
console.log("Error:", error);
process.exitCode=1;
})
// void async function() {
// try {
// const web3 = new Web3(new Web3.providers.HttpProvider(testnet));
// const balance = await web3.eth.getBalance(walletAddress);
// console.log('the balance is', web3.utils.fromWei(balance, 'ether'))
// } catch (error) {
// console.error(error)
// }
// }();