Skip to content

Instantly share code, notes, and snippets.

@johnpm-12
johnpm-12 / multicall-ethers.ts
Last active July 22, 2021 14:14
multicall example with ethers
import { ethers } from "ethers";
const provider = new ethers.providers.Web3Provider((window as any).ethereum);
const multiCallAddresses = {
1: "0xeefba1e63905ef1d7acba5a8513c70307c1ce441",
3: "0x53C43764255c17BD724F74c4eF150724AC50a3ed", // ropsten
4: "0x42ad527de7d4e9d9d011ac45b31d8551f8fe9821", // rinkeby
5: "0x77dca2c955b15e9de4dbbcf1246b4b85b651e50e", // goerli
42: "0x2cc8688c5f75e365aaeeb4ea8d6a480405a48d2a", // kovan
@johnpm-12
johnpm-12 / eip-2612-ethers.ts
Last active August 7, 2022 21:14
EIP-2612 ethers example
import { BigNumberish, Signature, utils, providers, Contract } from "ethers";
// this is designed to work with USDC
export async function signPermit(
signer: providers.JsonRpcSigner,
token: Contract,
chainId: BigNumberish,
spender: string,
value: BigNumberish,
deadline: BigNumberish
@johnpm-12
johnpm-12 / promise-all-object-values.ts
Created July 24, 2021 16:53
Promise.all for an object whose values are promises
// this function takes in an object whose values are all promises
// and returns a single promise that resolves to an object with all the same keys with resolved values
async function promiseAllObjectValues<T>(
object: {
[TK in keyof T]: Promise<T[TK]>;
}
): Promise<T> {
return Promise.all(
Object.entries(object).map(async ([name, promise]) => [
name,
@johnpm-12
johnpm-12 / compose.yml
Created January 13, 2025 22:15
mongo docker compose healthcheck
# I got tired of seeing examples of mongo healthchecks that weren't actually doing anything
# They appear to work only because the mongo server happens to be up by the time the first health check happens
# But they don't actually assess whether it's ok or not
# This one does
services:
mongo-express:
image: mongo-express:1.0
ports:
- 8081:8081