Skip to content

Instantly share code, notes, and snippets.

@MayowaObisesan
Last active August 5, 2023 17:06
Show Gist options
  • Save MayowaObisesan/0d8766d1c5e97126f3d6329dad536d41 to your computer and use it in GitHub Desktop.
Save MayowaObisesan/0d8766d1c5e97126f3d6329dad536d41 to your computer and use it in GitHub Desktop.
web3-weekone-assessment
import {ethers} from 'ethers';
const nodeProvider = "";
const getAccountType = (code) => {
const provider = ethers.getDefaultProvider(nodeProvider);
const code = provider.getCode(code);
return code;
}
// Import the web3.js library
const Web3 = require('web3');
const myInfuraID = "";
// Connect to a web3 provider (such as Infura)
const web3 = new Web3(`https://mainnet.infura.io/v3/${myInfuraID}`);
// A sample account address
const account = '0x742d35Cc6634C0532925a3b844Bc454e4438f44e';
// The account balance in wei (the smallest unit of ether)
web3.eth.getBalance(account, (error, balance) => {
if (error) {
console.error(error);
} else {
// Convert the balance from wei to ether and display it
console.log('Balance:', web3.utils.fromWei(balance, 'ether'), 'ETH');
}
});
// The account transaction count (the number of outgoing transactions)
web3.eth.getTransactionCount(account, (error, count) => {
if (error) {
console.error(error);
} else {
// Display the transaction count
console.log('Transaction count:', count);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment