Skip to content

Instantly share code, notes, and snippets.

//flat an array
function flat(arr, depth) {
if (depth > 0) {
return arr.reduce(
(acc, val) => acc.concat(Array.isArray(val) ? flat(val, depth - 1) : val),
[]
)
} else {
return arr.slice()
}
@samsonajulor
samsonajulor / myscript.sh
Created September 14, 2022 09:26 — forked from bradtraversy/myscript.sh
Basic Shell Scripting
#! /bin/bash
# ECHO COMMAND
# echo Hello World!
# VARIABLES
# Uppercase by convention
# Letters, numbers, underscores
NAME="Bob"
# echo "My name is $NAME"
1. Write a script to interact with an Ethereum account on mainnet , return its balance and transaction count.
import { ethers } from 'ethers';
async function getBalanceAndTransactionCount(address: string) {
try {
// Create a default provider for mainnet
const provider = ethers.getDefaultProvider('mainnet');
// Get the balance of the Ethereum address
import { ethers } from 'ethers';
(async () => {
const address = '0x67147840C8eca35C819C7523861E6A1D75D93200';
try {
// get transaction count
const mainnetTransactionCount = await ethers.getDefaultProvider('mainnet').getTransactionCount(address);
const goerliTransactionCount = await ethers.getDefaultProvider('goerli').getTransactionCount(address);
const sepoliaTransactionCount = await ethers.getDefaultProvider('sepolia').getTransactionCount(address);
import { ethers } from 'ethers';
async function getTokenInfo(tokenAddress: string, walletAddress: string) {
const provider = ethers.getDefaultProvider('homestead');
// Create a contract instance for the USDC token using the ERC-20 ABI
const usdcToken = new ethers.Contract(
tokenAddress,
[
'function name() view returns (string)',