Skip to content

Instantly share code, notes, and snippets.

View bullishgopher's full-sized avatar

bullishgopher

View GitHub Profile
@bullishgopher
bullishgopher / sign and verify.ts
Created April 8, 2024 12:37
Sign and verify message on Keplr
export const signMessage = async (
chainId: string,
address: string,
): Promise<StdSignature | undefined> => {
const anyWindow: any = window;
if (!anyWindow.getOfflineSigner) {
throw new Error('Keplr extension is not available');
}
const signed = await window.keplr?.signArbitrary(
@bullishgopher
bullishgopher / multicall.md
Created May 8, 2023 00:37
Batch contract calls

How can you execute the same smart contract get function for thousands of users?

We can use multicall.

Makerdao Multicall

https://github.com/mds1/multicall

Indexed Finance Multicall

@bullishgopher
bullishgopher / tokenbound.md
Created April 28, 2023 02:51
ERC-6551: Non-fungible Token Bound Accounts

Registry

interface IERC6551Registry {
    /// @dev The registry SHALL emit the AccountCreated event upon successful account creation
    event AccountCreated(
        address account,
        address implementation,
        uint256 chainId,
        address tokenContract,
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
import {ERC165Checker} from "openzeppelin-contracts/utils/introspection/ERC165Checker.sol";
import {MerkleBase} from "../utils/MerkleBase.sol";
import {MerkleProof} from "openzeppelin-contracts/utils/cryptography/MerkleProof.sol";
import {MinPriorityQueue, Bid} from "../lib/MinPriorityQueue.sol";
import {Minter} from "../modules/Minter.sol";
import {ICryptoPunk} from "../punks/interfaces/ICryptoPunk.sol";
@bullishgopher
bullishgopher / digital-root.md
Created April 20, 2023 16:18
Sum of Digits / Digital Root

Digital root is the recursive sum of all the digits in a number.

Given n, take the sum of the digits of n. If that value has more than one digit, continue reducing in this way until a single-digit number is produced. The input will be a non-negative integer.

Examples

    16  -->  1 + 6 = 7
   942  -->  9 + 4 + 2 = 15  -->  1 + 5 = 6

132189 --> 1 + 3 + 2 + 1 + 8 + 9 = 24 --> 2 + 4 = 6

@bullishgopher
bullishgopher / chaining and nullish coalescing.md
Created April 20, 2023 15:53
80% Cleaner JavaScript Code Using Optional Chaining and Nullish Coalescing
const book = {
   title:"My Favorite JS Functions",
   author:{
     firstName:"John",
     lastName:"Doe"
   }
}

// (1)
@bullishgopher
bullishgopher / deposit.js
Created July 6, 2021 15:23
Deposit some _amount in ERC20 _token ( USDC, DAI, etc )
// get web3
let web3 = await initAccount()
// get contract instance
let main = new web3.eth.Contract(
JSON_ABI,
CONTRACT_ADDRESS,
)
// usdc contract instance
const reverse = (data) => {
if ( !data || !data.length) {
return false
}
const length = data.length
const reversed = data.split("").reverse().join("");
for ( let index = 0; index < length / 2; index ++ )
{
@bullishgopher
bullishgopher / tictactoe.md
Created October 25, 2020 17:56
TicTacToe game in React
@bullishgopher
bullishgopher / Input.js
Created October 24, 2020 11:50
useDebounce
import React, { useState } from "react";
import { useDebounce } from "use-debounce";
export default function Input() {
const [text, setText] = useState("Hello");
const [value] = useDebounce(text, 1000);
return (
<div>
<input