Skip to content

Instantly share code, notes, and snippets.

View ZacharyCouchman's full-sized avatar

Zach Couchman ZacharyCouchman

View GitHub Profile
// dynamically load a script and wait for load event
async function loadScript(url) {
return new Promise((resolve, reject) => {
let ourScript = document.createElement('script');
ourScript.addEventListener('load', () => {
console.log('script was loaded');
resolve('awesome');
});
@ZacharyCouchman
ZacharyCouchman / dynamicallyLoadJS.js
Last active November 18, 2023 02:17
Dynamically load a script into the dom
function loadScript() {
// create a script element
let ourScript = document.createElement('script');
// add the src, where we are loading the script from
ourScript.src = "https://cdn.jsdelivr.net/...";
// append the script to the doucment head (load the script into the DOM)
document.head.appendChild(ourScript);
}
@ZacharyCouchman
ZacharyCouchman / inspectBlocks.js
Created April 1, 2023 04:16
Inspect the information and transactions within a block
import { ethers } from "ethers"
const rpcUrl = `https://eth-mainnet.g.alchemy.com/v2/demo`;
async function inspectBlocks(){
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const blockNumber = await provider.getBlockNumber();
console.log(blockNumber);
const previousBlock = await provider.getBlock(blockNumber - 1);
@ZacharyCouchman
ZacharyCouchman / queryEvents.js
Created April 1, 2023 04:14
Query events that have been emitted by the IMX contract
import { ethers } from 'ethers';
import { formatUnits } from 'ethers/lib/utils.js';
const rpcUrl = `https://eth-mainnet.g.alchemy.com/v2/demo`;
const imxERC20TokenAddress = "0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF";
const contractABI = [
"function name() view returns (string)",
"function symbol() view returns (string)",
@ZacharyCouchman
ZacharyCouchman / sendTransaction.js
Created April 1, 2023 03:56
Send ETH from one wallet to another
import { ethers } from "ethers";
import { formatEther, parseEther } from "ethers/lib/utils.js";
// As this demo is for sending funds, connect to the goerli test network to not spend real money
const rpcUrl = "https://eth-goerli.g.alchemy.com/v2/demo";
const wallet1PublicAddress = ""; // add the wallet address you want to send goerli ETH from
const wallet1PrivateKey = ""; // Do not expose this Private key. Only use a test wallet for this demo.
const wallet2PublicAddress = ""; // add the wallet address you want to send funds to
@ZacharyCouchman
ZacharyCouchman / getERC20Balance.js
Last active April 1, 2023 04:08
Get ERC20 token balance of a wallet
import { ethers } from "ethers";
import { formatUnits } from "ethers/lib/utils.js";
const walletAddress = ""; // add the wallet address you want to check the balance of
const rpcUrl = "https://eth-mainnet.g.alchemy.com/v2/demo;
const imxERC20TokenAddress = "0xF57e7e7C23978C3cAEC3C3548E3D615c346e79fF"; // Immutable X ERC20 token contract address
const contractABI = [
"function name() view returns (string)",
"function symbol() view returns (string)",
@ZacharyCouchman
ZacharyCouchman / getWalletBalance.js
Created April 1, 2023 03:43
Getting the ETH balance of a wallet
import { ethers } from "ethers"
import { formatEther } from "ethers/lib/utils.js";
const walletAddress = ""; // add the wallet address you want to check the balance of
const rpcUrl = "https://eth-mainnet.g.alchemy.com/v2/demo";
async function getWalletBalance(){
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
const balance = await provider.getBalance(walletAddress);
@ZacharyCouchman
ZacharyCouchman / CustomAngularMaterialTheme.scss
Created February 16, 2019 21:14
How to include a custom material design theme to your angular project
@import "~@angular/material/theming";
@include mat-core();
// Standard material custom theme setup
$primary: mat-palette($mat-blue, 800, 500, 900);
$accent: mat-palette($mat-pink, 500, 300, 700);
$warn: mat-palette($mat-red, 700);
$my-theme: mat-light-theme($primary, $accent, $warn);
@ZacharyCouchman
ZacharyCouchman / StartupDatabaseMigration
Last active February 11, 2019 09:39
Adding the below line into the ConfigureServices method of the Startup.cs file will call EF migrations to run on app startup.
using Microsoft.EntityFrameworkCore;
...
public void ConfigureServices(IServiceCollection services)
{
// Add other services here
// Add the database context to the services collection for dependency injection
services.AddDbContext<MyDatabaseContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DatabaseConnectionString")));
@ZacharyCouchman
ZacharyCouchman / CreateDatabaseMigrations.xml
Last active February 7, 2019 10:43
Create EF Core database migrations as a single idempotent SQL script
// Paste this snippet in your .NET Core main .csproj file
// Change (or remove) the Condition statement if you want this to run on Debug builds (locally) as well
<Target Name="Create Migrations Script" AfterTargets="PostBuildEvent" Condition="'$(Configuration)' == 'Release'">
<Exec Command="dotnet ef migrations script --configuration $(Configuration) --no-build --idempotent --output $(TargetDir)/migrations.sql"/>
</Target>