Skip to content

Instantly share code, notes, and snippets.

Avatar

karmacoma karmacoma-eth

View GitHub Profile
View sending-ether-cheat-sheet.md

Sending Ether Cheat Sheet

TLDR

🥇 Instead of sending Ether, use the withdrawal pattern

🥈 If you really need to send Ether, use a safe wrapper like OpenZeppelin's Address.sendValue(addr, amount)

🥉 If you really need to send Ether without dependencies, use (bool success, ) = addr.call{value: amount}("")

View quine.etk
# quine.etk
# ⬜ => ⬜
# A quine is a computer program which takes no input and produces a copy of its own source code as its only output.
# 0x80...f3 is the compiled code excluding the push16 instruction (from dup1 to return)
push16 0x8060801b17606f5953600152602136f3
# --- stack ---
dup1 # code code
push1 128 # 128 code code
@karmacoma-eth
karmacoma-eth / parallel-wait.py
Created Jul 29, 2022
starts n processes with some random amount of work, and they exit whenever the first one is finished
View parallel-wait.py
import os
import random
import time
from multiprocessing import Pool, Event
def init_pool_processes(the_shutdown_event):
'''
Initialize each process with the global shutdown event
@karmacoma-eth
karmacoma-eth / AdversarialRoyalties.sol
Created Feb 15, 2022
What if a contract returns different data when viewed off-chain vs during a transaction?
View AdversarialRoyalties.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
contract AdversarialRoyalties {
bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;
function supportsInterface(bytes4 interfaceID) external pure returns (bool) {
return interfaceID == _INTERFACE_ID_ERC2981;
}
@karmacoma-eth
karmacoma-eth / CheckBeforeStore.sol
Created Feb 8, 2022
Is it cheaper to check if a new value is different before storing it?
View CheckBeforeStore.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.0;
contract CheckBeforeStore {
event Log(address);
bytes32 stored;
function setUp() public {
stored = keccak256(abi.encode(address(this)));
@karmacoma-eth
karmacoma-eth / IERC1155MetadataURI.json
Created Sep 20, 2021
IERC1155MetadataURI JSON ABI
View IERC1155MetadataURI.json
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "account",
"type": "address"
},