For smart contract development · Copy-paste ready
Battle-tested Solidity snippets covering ERC-20, ERC-721, access control, upgrades, events, payments, utilities, and Yul assembly. Each snippet includes an explanation and gas notes. Compatible with Solidity 0.8.20+ and OpenZeppelin v5.
function safeTransfer(address token, address to, uint256 amount)
internal
returns (bool)
{
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(IERC20.transfer.selector, to, amount)
);
return success && (data.length == 0 || abi.decode(data, (bool)));
}
modifier onlyRole(bytes32 role) {
require(hasRole(role, msg.sender), "Access denied");
_;
}
bytes32 public constant ADMIN = keccak256("ADMIN");
bytes32 public constant MINTER = keccak256("MINTER");
function splitPayment(address[] calldata recipients, uint256[] calldata shares)
external
payable
{
uint256 total = 0;
for (uint256 i = 0; i < shares.length; i++) total += shares[i];
require(msg.value == total, "Mismatch");
for (uint256 i = 0; i < recipients.length; i++)
payable(recipients[i]).transfer(shares[i]);
}
function lazyMint(
address to,
uint256 tokenId,
bytes calldata signature
) external {
bytes32 msgHash = keccak256(abi.encode(to, tokenId));
bytes32 ethSignedHash = ECDSA.toEthSignedMessageHash(msgHash);
address signer = ECDSA.recover(ethSignedHash, signature);
require(signer == minter, "Invalid sig");
_safeMint(to, tokenId);
}
function _authorizeUpgrade(address newImplementation)
internal
override
onlyRole(UPGRADER)
{}
uint256[50] private __gap;
+25 more snippets across 8 categories.
A PDF with 30 copy-paste-ready Solidity snippets covering ERC-20, ERC-721, access control, upgrades, events, payments, utilities, and Yul assembly. Each snippet includes an explanation and gas notes.
Send exactly $1 in ETH to the address below. After the transaction confirms, email me your wallet address and I'll send you the PDF within 24 hours.
0.8.20+. Snippets avoid deprecated patterns and are compatible with OpenZeppelin v5.
Full refund within 7 days if the snippets don't save you time. Just show me the tx hash.
Send exactly $1 in ETH to:
0x0D42B32D6E21F496082104BFC8d7213081474577
Ethereum mainnet · ERC-20 compatible
© 2025 · 30 Solidity Snippets