-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkEthers.js
29 lines (22 loc) · 939 Bytes
/
checkEthers.js
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
const { ethers } = require('ethers');
const { AlchemyProvider } = require('@alch/alchemy-web3');
// Ganti dengan Alchemy API Key Anda
const alchemyApiKey = 'YOUR_ALCHEMY_API_KEY';
// Ganti dengan alamat dompet Ethereum yang ingin Anda periksa saldonya
const walletAddress = 'YOUR_ETH_WALLET_ADDRESS';
// Inisialisasi provider menggunakan Alchemy
const alchemyProvider = new AlchemyProvider('mainnet', alchemyApiKey);
// Fungsi untuk memeriksa saldo Ether
async function checkBalance() {
try {
// Dapatkan saldo Ether menggunakan alamat dompet
const balance = await alchemyProvider.getBalance(walletAddress);
// Konversi saldo dari wei ke Ether
const etherBalance = ethers.utils.formatEther(balance);
console.log(`Saldo Ether dari alamat ${walletAddress}: ${etherBalance} ETH`);
} catch (error) {
console.error('Error:', error.message);
}
}
// Panggil fungsi untuk memeriksa saldo Ether
checkBalance();