Skip to content

Instantly share code, notes, and snippets.

declare const window: any
// account is the ethereum address
export const signMessage = async (account: string, message: string) => {
const { ethereum } = window
if (!ethereum) return
try {
const signature = await window.ethereum.request({
method: 'personal_sign',
params: [account, message],
declare const window: any
const chainIds: {
[chainId: string]: string
} = {
ethereum: '0x1',
bsc: '0x38',
}
const rpcUrls: {
@o-az
o-az / ethereum_chains.json
Created December 22, 2021 21:57
All Ethereum chains info & metadata
[
{
"name": "Ethereum Mainnet",
"chain": "ETH",
"network": "mainnet",
"icon": "ethereum",
"rpc": [
"https://mainnet.infura.io/v3/${INFURA_API_KEY}",
"wss://mainnet.infura.io/ws/v3/${INFURA_API_KEY}",
"https://api.mycryptoapi.com/eth",
@o-az
o-az / use-named-lazy-import.tsx
Created December 24, 2021 05:09
Lets you React.lazy import named exports
import * as React from 'react'
function lazyImport<
T extends React.ComponentType<any>,
I extends { [K2 in K]: T },
K extends keyof I
>(factory: () => Promise<I>, name: K): I {
return Object.create({
[name]: React.lazy(() =>
factory().then(module => ({ default: module[name] }))
@o-az
o-az / index.js
Created August 2, 2021 14:45
Simple React Context
import React from "react";
import ReactDOM from "react-dom";
// set the defaults
const LanguageContext = React.createContext({
language: "en",
setLanguage: () => {}
});
const LanguageSwitcher = () => {
@o-az
o-az / avatar.png
Last active January 13, 2022 17:18
avatar.png
@o-az
o-az / useDetectAccountChange.ts
Created February 19, 2022 06:44
a react custom hook to detect account change and do things
import * as React from 'react';
import { providers } from 'ethers';
const logout = async () =>
axios
.get('/api/auth/logout')
.then(_ => _)
.catch(_ => console.log(_));
export const useDetectAccountChange = () => {
@o-az
o-az / object.keys_literal_types.ts
Created March 30, 2022 07:16
Object.keys(obj) array to string literal types
// don't use this. I'm not sure if this is a good solution
// keeping it as notes till I find a better solution
// assume you got this from a JSON file:
const statesWeather = {
"wisconsin": "cloudy",
"california": "rainy",
"newyork": "sunny",
"florida": "cloudy",
"texas": "rainy",
@o-az
o-az / add-link-tag.ts
Last active May 26, 2022 06:45
Dynamically add <link /> tag to your HTML page
title publishedOn description
Hello World
2022-05-15
T3st1ng G1thub G15t5 as CeeDee En

Quick Maths:

$$ L = \frac{1}{2} \rho v^2 S C_L