Skip to content

Instantly share code, notes, and snippets.

View karmacoma-eth's full-sized avatar

karmacoma karmacoma-eth

View GitHub Profile
@karmacoma-eth
karmacoma-eth / AdversarialRoyalties.sol
Created February 15, 2022 02:26
What if a contract returns different data when viewed off-chain vs during a transaction?
// 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 February 8, 2022 19:08
Is it cheaper to check if a new value is different before storing it?
// 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 / sending-ether-cheat-sheet.md
Last active March 12, 2024 01:14
Sending Ether Cheat Sheet

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}("")

@karmacoma-eth
karmacoma-eth / IERC1155MetadataURI.json
Created September 20, 2021 22:33
IERC1155MetadataURI JSON ABI
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "account",
"type": "address"
},