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
// 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 : ""
async function method1(payload) {
return Buffer.from(payload, 'base64').toString('utf-8');
}
async function method2(payload) {
const uint8_array = await ethers.utils.base64.decode(payload);
const char_array = Array.from(uint8_array).map((element) => {
return String.fromCharCode(element)
});
@a2468834
a2468834 / Example2.sol
Last active May 16, 2022 02:09
2022-05-16 HSNL Paper Meeting
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract Victim {
mapping(address => uint256) public balances;
function deposit() public payable {
balances[msg.sender] += msg.value;
}
@a2468834
a2468834 / Example1.sol
Last active May 16, 2022 02:03
2022-05-16 HSNL Paper Meeting
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract A {
uint256 public x;
function foo() public payable {
x++;
}