Secure Smart Contract library providing battle-tested implementations of industry-standard Solidity contracts including ERC20, ERC721, ERC1155 tokens, access control mechanisms, proxy patterns, and governance systems for Ethereum and EVM-compatible blockchains.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
OpenZeppelin Contracts provides complete implementations of all major Ethereum token standards with extensive extensions, utilities, and preset configurations.
contract ERC20 is Context, IERC20, IERC20Metadata {
constructor(string memory name_, string memory symbol_);
function name() public view virtual override returns (string memory);
function symbol() public view virtual override returns (string memory);
function decimals() public view virtual override returns (uint8);
function totalSupply() public view virtual override returns (uint256);
function balanceOf(address account) public view virtual override returns (uint256);
function transfer(address to, uint256 amount) public virtual override returns (bool);
function allowance(address owner, address spender) public view virtual override returns (uint256);
function approve(address spender, uint256 amount) public virtual override returns (bool);
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool);
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool);
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool);
}
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}Events:
Transfer(address indexed from, address indexed to, uint256 value)Approval(address indexed owner, address indexed spender, uint256 value)Allows token holders to burn their tokens.
contract ERC20Burnable is Context, ERC20 {
function burn(uint256 amount) public virtual;
function burnFrom(address account, uint256 amount) public virtual;
}ERC20 with a maximum supply cap.
contract ERC20Capped is ERC20 {
constructor(uint256 cap_);
function cap() public view virtual returns (uint256);
}ERC20 with pausable transfers.
contract ERC20Pausable is ERC20, Pausable {
// Inherits all ERC20 and Pausable functions
}Allows taking snapshots of balances at specific points in time.
contract ERC20Snapshot is ERC20 {
function snapshot() public returns (uint256);
function balanceOfAt(address account, uint256 snapshotId) public view returns (uint256);
function totalSupplyAt(uint256 snapshotId) public view returns (uint256);
}Events:
Snapshot(uint256 id)Adds voting functionality with delegation support.
contract ERC20Votes is IVotes, ERC20Permit {
function getVotes(address account) public view virtual override returns (uint256);
function getPastVotes(address account, uint256 blockNumber) public view virtual override returns (uint256);
function getPastTotalSupply(uint256 blockNumber) public view virtual override returns (uint256);
function delegates(address account) public view virtual override returns (address);
function delegate(address delegatee) public virtual override;
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) public virtual override;
}Events:
DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate)DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance)Compound-compatible voting extension with 96-bit supply limitation for exact compatibility with Compound Governor Alpha and Bravo.
abstract contract ERC20VotesComp is ERC20Votes {
function getCurrentVotes(address account) external view virtual returns (uint96);
function getPriorVotes(address account, uint256 blockNumber) external view virtual returns (uint96);
}Note: Use this contract when you need exact compatibility with COMP token and Compound governance systems. For new implementations without legacy compatibility requirements, use ERC20Votes instead.
Wraps an underlying ERC20 token.
contract ERC20Wrapper is ERC20 {
constructor(IERC20 underlyingToken);
function underlying() public view returns (IERC20);
function depositFor(address account, uint256 amount) public virtual returns (bool);
function withdrawTo(address account, uint256 amount) public virtual returns (bool);
function recover(address account) public virtual returns (uint256);
}Adds flash minting capabilities.
contract ERC20FlashMint is ERC20, IERC3156FlashLender {
function maxFlashLoan(address token) public view virtual override returns (uint256);
function flashFee(address token, uint256 amount) public view virtual override returns (uint256);
function flashLoan(IERC3156FlashBorrower receiver, address token, uint256 amount, bytes calldata data) public virtual override returns (bool);
}Gasless approvals using signatures.
contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override;
function nonces(address owner) public view virtual override returns (uint256);
function DOMAIN_SEPARATOR() external view override returns (bytes32);
}contract ERC4626 is Context, ERC165, IERC4626, ERC20 {
constructor(IERC20 asset_, string memory name_, string memory symbol_);
function asset() public view virtual override returns (address assetTokenAddress);
function totalAssets() public view virtual override returns (uint256 totalManagedAssets);
function convertToShares(uint256 assets) public view virtual override returns (uint256 shares);
function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets);
function maxDeposit(address receiver) public view virtual override returns (uint256 maxAssets);
function previewDeposit(uint256 assets) public view virtual override returns (uint256 shares);
function deposit(uint256 assets, address receiver) public virtual override returns (uint256 shares);
function maxMint(address receiver) public view virtual override returns (uint256 maxShares);
function previewMint(uint256 shares) public view virtual override returns (uint256 assets);
function mint(uint256 shares, address receiver) public virtual override returns (uint256 assets);
function maxWithdraw(address owner) public view virtual override returns (uint256 maxAssets);
function previewWithdraw(uint256 assets) public view virtual override returns (uint256 shares);
function withdraw(uint256 assets, address receiver, address owner) public virtual override returns (uint256 shares);
function maxRedeem(address owner) public view virtual override returns (uint256 maxShares);
function previewRedeem(uint256 shares) public view virtual override returns (uint256 assets);
function redeem(uint256 shares, address receiver, address owner) public virtual override returns (uint256 assets);
}Events:
Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares)Withdraw(address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares)Safe wrappers around ERC20 operations that revert on failure.
library SafeERC20 {
function safeTransfer(IERC20 token, address to, uint256 value) internal;
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal;
function safeApprove(IERC20 token, address spender, uint256 value) internal;
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal;
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal;
}Time-locked token holder contract.
contract TokenTimelock {
constructor(IERC20 token_, address beneficiary_, uint256 releaseTime_);
function token() public view virtual returns (IERC20);
function beneficiary() public view virtual returns (address);
function releaseTime() public view virtual returns (uint256);
function release() public virtual;
}Simple ERC20 token with fixed supply.
contract ERC20PresetFixedSupply is ERC20Burnable {
constructor(string memory name, string memory symbol, uint256 initialSupply, address owner);
}ERC20 token with minting and pausing capabilities.
contract ERC20PresetMinterPauser is Context, AccessControlEnumerable, ERC20Burnable, ERC20Pausable {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
constructor(string memory name, string memory symbol);
function mint(address to, uint256 amount) public virtual;
function pause() public virtual;
function unpause() public virtual;
}contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
constructor(string memory name_, string memory symbol_);
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);
function balanceOf(address owner) public view virtual override returns (uint256);
function ownerOf(uint256 tokenId) public view virtual override returns (address);
function name() public view virtual override returns (string memory);
function symbol() public view virtual override returns (string memory);
function tokenURI(uint256 tokenId) public view virtual override returns (string memory);
function approve(address to, uint256 tokenId) public virtual override;
function getApproved(uint256 tokenId) public view virtual override returns (address);
function setApprovalForAll(address operator, bool approved) public virtual override;
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool);
function transferFrom(address from, address to, uint256 tokenId) public virtual override;
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override;
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override;
}Allows NFT burning.
contract ERC721Burnable is Context, ERC721 {
function burn(uint256 tokenId) public virtual;
}Adds enumeration capabilities to NFTs.
contract ERC721Enumerable is ERC721, IERC721Enumerable {
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool);
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256);
function totalSupply() public view virtual override returns (uint256);
function tokenByIndex(uint256 index) public view virtual override returns (uint256);
}Pausable NFT transfers.
contract ERC721Pausable is ERC721, Pausable {
// Inherits all ERC721 and Pausable functions
}Per-token URI storage.
contract ERC721URIStorage is ERC721 {
function tokenURI(uint256 tokenId) public view virtual override returns (string memory);
}NFT with voting capabilities.
contract ERC721Votes is ERC721, Votes {
function getVotes(address account) public view virtual override returns (uint256);
function getPastVotes(address account, uint256 blockNumber) public view virtual override returns (uint256);
function getPastTotalSupply(uint256 blockNumber) public view virtual override returns (uint256);
function delegates(address account) public view virtual override returns (address);
function delegate(address delegatee) public virtual override;
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) public virtual override;
}NFT with EIP2981 royalty support.
contract ERC721Royalty is ERC721, ERC2981 {
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC2981) returns (bool);
}Batch minting of consecutive NFTs.
abstract contract ERC721Consecutive is ERC721 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool);
function ownerOf(uint256 tokenId) public view virtual override returns (address);
}Events:
ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed fromAddress, address indexed toAddress)Safe NFT receiver contract.
contract ERC721Holder is IERC721Receiver {
function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4);
}NFT with auto-incrementing IDs, minting and pausing.
contract ERC721PresetMinterPauserAutoId is Context, AccessControlEnumerable, ERC721Burnable, ERC721Pausable {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
constructor(string memory name, string memory symbol, string memory baseTokenURI);
function mint(address to) public virtual;
function pause() public virtual;
function unpause() public virtual;
}contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
constructor(string memory uri_);
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);
function uri(uint256) public view virtual override returns (string memory);
function balanceOf(address account, uint256 id) public view virtual override returns (uint256);
function balanceOfBatch(address[] memory accounts, uint256[] memory ids) public view virtual override returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) public virtual override;
function isApprovedForAll(address account, address operator) public view virtual override returns (bool);
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes memory data) public virtual override;
function safeBatchTransferFrom(address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public virtual override;
}Allows multi-token burning.
contract ERC1155Burnable is ERC1155 {
function burn(address account, uint256 id, uint256 value) public virtual;
function burnBatch(address account, uint256[] memory ids, uint256[] memory values) public virtual;
}Pausable multi-token transfers.
contract ERC1155Pausable is ERC1155, Pausable {
// Inherits all ERC1155 and Pausable functions
}Supply tracking for multi-tokens.
contract ERC1155Supply is ERC1155 {
function totalSupply(uint256 id) public view virtual returns (uint256);
function exists(uint256 id) public view virtual returns (bool);
}Per-token URI storage for multi-tokens.
contract ERC1155URIStorage is ERC1155 {
function uri(uint256 tokenId) public view virtual override returns (string memory);
}Safe multi-token receiver contract.
contract ERC1155Holder is ERC1155Receiver {
function onERC1155Received(address, address, uint256, uint256, bytes memory) public virtual override returns (bytes4);
function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory) public virtual override returns (bytes4);
}Multi-token with minting and pausing.
contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155Burnable, ERC1155Pausable {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
constructor(string memory uri);
function mint(address to, uint256 id, uint256 amount, bytes memory data) public virtual;
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public virtual;
function pause() public virtual;
function unpause() public virtual;
}contract ERC777 is Context, IERC777, IERC20 {
constructor(string memory name_, string memory symbol_, address[] memory defaultOperators_);
function name() public view virtual override returns (string memory);
function symbol() public view virtual override returns (string memory);
function decimals() public pure virtual returns (uint8);
function granularity() public view virtual override returns (uint256);
function totalSupply() public view virtual override(IERC20, IERC777) returns (uint256);
function balanceOf(address tokenHolder) public view virtual override(IERC20, IERC777) returns (uint256 balance);
function send(address recipient, uint256 amount, bytes memory data) public virtual override;
function burn(uint256 amount, bytes memory data) public virtual override;
function isOperatorFor(address operator, address tokenHolder) public view virtual override returns (bool);
function authorizeOperator(address operator) public virtual override;
function revokeOperator(address operator) public virtual override;
function defaultOperators() public view virtual override returns (address[] memory);
function operatorSend(address sender, address recipient, uint256 amount, bytes memory data, bytes memory operatorData) public virtual override;
function operatorBurn(address account, uint256 amount, bytes memory data, bytes memory operatorData) public virtual override;
function allowance(address holder, address spender) public view virtual override returns (uint256);
function approve(address spender, uint256 value) public virtual override returns (bool);
function transfer(address to, uint256 value) public virtual override returns (bool);
function transferFrom(address from, address to, uint256 value) public virtual override returns (bool);
}Events:
Sent(address indexed operator, address indexed from, address indexed to, uint256 amount, bytes data, bytes operatorData)Minted(address indexed operator, address indexed to, uint256 amount, bytes data, bytes operatorData)Burned(address indexed operator, address indexed from, uint256 amount, bytes data, bytes operatorData)AuthorizedOperator(address indexed operator, address indexed holder)RevokedOperator(address indexed operator, address indexed holder)ERC777 token with fixed supply.
contract ERC777PresetFixedSupply is ERC777 {
constructor(string memory name, string memory symbol, address[] memory defaultOperators, uint256 initialSupply, address owner);
}abstract contract ERC2981 is IERC2981, ERC165 {
struct RoyaltyInfo {
address receiver;
uint96 royaltyFraction;
}
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool);
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) public view virtual override returns (address, uint256);
}Events:
RoyaltySet(uint256 indexed tokenId, address indexed recipient, uint256 amount)Install with Tessl CLI
npx tessl i tessl/npm-openzeppelin-solidity