Skip to content

Instantly share code, notes, and snippets.

View a2468834's full-sized avatar
🤗
Search for opportunities

Chuan-Chun Wang a2468834

🤗
Search for opportunities
View GitHub Profile
package main
import (
"context"
"encoding/base64"
"fmt"
"io"
"net/http"
"runtime/debug"
"strings"
@a2468834
a2468834 / Example.ts
Last active September 26, 2024 16:13
import { Address, beginCell } from "@ton/ton";
import { mnemonicToPrivateKey, sign, sha256, signVerify } from "@ton/crypto";
import assert from "assert";
// Type
type LessThan<N extends number, A extends any[] = []> = N extends A['length'] ? A[number] : LessThan<N, [...A, A['length']]>;
type RangeOf<F extends number, T extends number> = Exclude<T | LessThan<T>, LessThan<F>>
type AtomicType = `int${RangeOf<0, 257>}` | `uint${RangeOf<0, 256>}` | "slice" | "cell";
type TypeDefinition = Record<string, Array<{ name: string, type: string | AtomicType }>>;
@a2468834
a2468834 / Example.fc
Last active September 26, 2024 16:05
;;
;; Example verifying signature smart contract in FunC
;;
;;
;; Storage layout
;;
;; uint256 public key: Signer's public key
;; uint32 nonce: A monotonic increasing uint counter starting from zero
;;
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MyToken is ERC20 {
constructor() ERC20("MyToken", "MTK") {}
function mint(address to, uint256 amount) public {
_mint(to, amount);
@a2468834
a2468834 / UUID4.sol
Last active May 10, 2023 15:50
Generate UUID4 strings from `block.prevrandao`.
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
/**
* Generate UUID strings from `block.difficulty`, i.e., `block.prevrandao`
*
* UUID follows RFC4122 Version-4 Variant-1 (DCE 1.1, ISO/IEC 11578:1996)
*
* See more at https://datatracker.ietf.org/doc/html/rfc4122.html
*/
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
contract C {
struct MerkleRoot {
bytes32 data;
bytes32 signatures;
}
@a2468834
a2468834 / chainlink-vrf-v1.sol
Created November 23, 2022 17:23
A smart contract that can interact with Chainlink VRF V1.
@a2468834
a2468834 / prev_randao.py
Last active April 28, 2023 03:19
Calculate next slot prev_randao
import hashlib
import string
##### Helper function #####
ssz_byteorder = "little" # https://github.com/ethereum/consensus-specs/blob/dev/ssz/simple-serialize.md
# https://github.com/ethereum/consensus-specs/blob/dev/ssz/simple-serialize.md#aliases
def isBytesN(input_):
# BytesN := Vector[uint8, N]
assert isinstance(input_, list)
// Import
const Web3 = require("web3");
// Constants
const USDC_mainnet = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
const Provider_URL = "wss://eth-mainnet.alchemyapi.io/v2/";
async function eventSubscribe() {
const web3 = new Web3(Provider_URL);
from web3 import Web3 # Use version 5.29.2
from web3.middleware import geth_poa_middleware
import json
class CONST:
def ABI():
with open("./WrappedEther.json") as f:
return json.load(f)
NodeProvider = lambda : "https://"
WrappedEther = lambda : ""