0
# Token Standards
1
2
OpenZeppelin Contracts provides complete implementations of all major Ethereum token standards with extensive extensions, utilities, and preset configurations.
3
4
## ERC20 Fungible Tokens
5
6
### Core ERC20 Implementation
7
8
```solidity { .api }
9
contract ERC20 is Context, IERC20, IERC20Metadata {
10
constructor(string memory name_, string memory symbol_);
11
12
function name() public view virtual override returns (string memory);
13
function symbol() public view virtual override returns (string memory);
14
function decimals() public view virtual override returns (uint8);
15
function totalSupply() public view virtual override returns (uint256);
16
function balanceOf(address account) public view virtual override returns (uint256);
17
function transfer(address to, uint256 amount) public virtual override returns (bool);
18
function allowance(address owner, address spender) public view virtual override returns (uint256);
19
function approve(address spender, uint256 amount) public virtual override returns (bool);
20
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool);
21
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool);
22
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool);
23
}
24
25
interface IERC20Metadata is IERC20 {
26
function name() external view returns (string memory);
27
function symbol() external view returns (string memory);
28
function decimals() external view returns (uint8);
29
}
30
```
31
32
**Events:**
33
- `Transfer(address indexed from, address indexed to, uint256 value)`
34
- `Approval(address indexed owner, address indexed spender, uint256 value)`
35
36
### ERC20 Extensions
37
38
#### ERC20Burnable
39
40
Allows token holders to burn their tokens.
41
42
```solidity { .api }
43
contract ERC20Burnable is Context, ERC20 {
44
function burn(uint256 amount) public virtual;
45
function burnFrom(address account, uint256 amount) public virtual;
46
}
47
```
48
49
#### ERC20Capped
50
51
ERC20 with a maximum supply cap.
52
53
```solidity { .api }
54
contract ERC20Capped is ERC20 {
55
constructor(uint256 cap_);
56
57
function cap() public view virtual returns (uint256);
58
}
59
```
60
61
#### ERC20Pausable
62
63
ERC20 with pausable transfers.
64
65
```solidity { .api }
66
contract ERC20Pausable is ERC20, Pausable {
67
// Inherits all ERC20 and Pausable functions
68
}
69
```
70
71
#### ERC20Snapshot
72
73
Allows taking snapshots of balances at specific points in time.
74
75
```solidity { .api }
76
contract ERC20Snapshot is ERC20 {
77
function snapshot() public returns (uint256);
78
function balanceOfAt(address account, uint256 snapshotId) public view returns (uint256);
79
function totalSupplyAt(uint256 snapshotId) public view returns (uint256);
80
}
81
```
82
83
**Events:**
84
- `Snapshot(uint256 id)`
85
86
#### ERC20Votes
87
88
Adds voting functionality with delegation support.
89
90
```solidity { .api }
91
contract ERC20Votes is IVotes, ERC20Permit {
92
function getVotes(address account) public view virtual override returns (uint256);
93
function getPastVotes(address account, uint256 blockNumber) public view virtual override returns (uint256);
94
function getPastTotalSupply(uint256 blockNumber) public view virtual override returns (uint256);
95
function delegates(address account) public view virtual override returns (address);
96
function delegate(address delegatee) public virtual override;
97
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) public virtual override;
98
}
99
```
100
101
**Events:**
102
- `DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate)`
103
- `DelegateVotesChanged(address indexed delegate, uint256 previousBalance, uint256 newBalance)`
104
105
#### ERC20VotesComp
106
107
Compound-compatible voting extension with 96-bit supply limitation for exact compatibility with Compound Governor Alpha and Bravo.
108
109
```solidity { .api }
110
abstract contract ERC20VotesComp is ERC20Votes {
111
function getCurrentVotes(address account) external view virtual returns (uint96);
112
function getPriorVotes(address account, uint256 blockNumber) external view virtual returns (uint96);
113
}
114
```
115
116
**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.
117
118
#### ERC20Wrapper
119
120
Wraps an underlying ERC20 token.
121
122
```solidity { .api }
123
contract ERC20Wrapper is ERC20 {
124
constructor(IERC20 underlyingToken);
125
126
function underlying() public view returns (IERC20);
127
function depositFor(address account, uint256 amount) public virtual returns (bool);
128
function withdrawTo(address account, uint256 amount) public virtual returns (bool);
129
function recover(address account) public virtual returns (uint256);
130
}
131
```
132
133
#### ERC20FlashMint
134
135
Adds flash minting capabilities.
136
137
```solidity { .api }
138
contract ERC20FlashMint is ERC20, IERC3156FlashLender {
139
function maxFlashLoan(address token) public view virtual override returns (uint256);
140
function flashFee(address token, uint256 amount) public view virtual override returns (uint256);
141
function flashLoan(IERC3156FlashBorrower receiver, address token, uint256 amount, bytes calldata data) public virtual override returns (bool);
142
}
143
```
144
145
#### ERC20Permit (Draft)
146
147
Gasless approvals using signatures.
148
149
```solidity { .api }
150
contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
151
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override;
152
function nonces(address owner) public view virtual override returns (uint256);
153
function DOMAIN_SEPARATOR() external view override returns (bytes32);
154
}
155
```
156
157
### ERC4626 Tokenized Vault
158
159
```solidity { .api }
160
contract ERC4626 is Context, ERC165, IERC4626, ERC20 {
161
constructor(IERC20 asset_, string memory name_, string memory symbol_);
162
163
function asset() public view virtual override returns (address assetTokenAddress);
164
function totalAssets() public view virtual override returns (uint256 totalManagedAssets);
165
function convertToShares(uint256 assets) public view virtual override returns (uint256 shares);
166
function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets);
167
function maxDeposit(address receiver) public view virtual override returns (uint256 maxAssets);
168
function previewDeposit(uint256 assets) public view virtual override returns (uint256 shares);
169
function deposit(uint256 assets, address receiver) public virtual override returns (uint256 shares);
170
function maxMint(address receiver) public view virtual override returns (uint256 maxShares);
171
function previewMint(uint256 shares) public view virtual override returns (uint256 assets);
172
function mint(uint256 shares, address receiver) public virtual override returns (uint256 assets);
173
function maxWithdraw(address owner) public view virtual override returns (uint256 maxAssets);
174
function previewWithdraw(uint256 assets) public view virtual override returns (uint256 shares);
175
function withdraw(uint256 assets, address receiver, address owner) public virtual override returns (uint256 shares);
176
function maxRedeem(address owner) public view virtual override returns (uint256 maxShares);
177
function previewRedeem(uint256 shares) public view virtual override returns (uint256 assets);
178
function redeem(uint256 shares, address receiver, address owner) public virtual override returns (uint256 assets);
179
}
180
```
181
182
**Events:**
183
- `Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares)`
184
- `Withdraw(address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares)`
185
186
### ERC20 Utilities
187
188
#### SafeERC20
189
190
Safe wrappers around ERC20 operations that revert on failure.
191
192
```solidity { .api }
193
library SafeERC20 {
194
function safeTransfer(IERC20 token, address to, uint256 value) internal;
195
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal;
196
function safeApprove(IERC20 token, address spender, uint256 value) internal;
197
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal;
198
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal;
199
}
200
```
201
202
#### TokenTimelock
203
204
Time-locked token holder contract.
205
206
```solidity { .api }
207
contract TokenTimelock {
208
constructor(IERC20 token_, address beneficiary_, uint256 releaseTime_);
209
210
function token() public view virtual returns (IERC20);
211
function beneficiary() public view virtual returns (address);
212
function releaseTime() public view virtual returns (uint256);
213
function release() public virtual;
214
}
215
```
216
217
### ERC20 Presets
218
219
#### ERC20PresetFixedSupply
220
221
Simple ERC20 token with fixed supply.
222
223
```solidity { .api }
224
contract ERC20PresetFixedSupply is ERC20Burnable {
225
constructor(string memory name, string memory symbol, uint256 initialSupply, address owner);
226
}
227
```
228
229
#### ERC20PresetMinterPauser
230
231
ERC20 token with minting and pausing capabilities.
232
233
```solidity { .api }
234
contract ERC20PresetMinterPauser is Context, AccessControlEnumerable, ERC20Burnable, ERC20Pausable {
235
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
236
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
237
238
constructor(string memory name, string memory symbol);
239
240
function mint(address to, uint256 amount) public virtual;
241
function pause() public virtual;
242
function unpause() public virtual;
243
}
244
```
245
246
## ERC721 Non-Fungible Tokens
247
248
### Core ERC721 Implementation
249
250
```solidity { .api }
251
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
252
constructor(string memory name_, string memory symbol_);
253
254
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);
255
function balanceOf(address owner) public view virtual override returns (uint256);
256
function ownerOf(uint256 tokenId) public view virtual override returns (address);
257
function name() public view virtual override returns (string memory);
258
function symbol() public view virtual override returns (string memory);
259
function tokenURI(uint256 tokenId) public view virtual override returns (string memory);
260
function approve(address to, uint256 tokenId) public virtual override;
261
function getApproved(uint256 tokenId) public view virtual override returns (address);
262
function setApprovalForAll(address operator, bool approved) public virtual override;
263
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool);
264
function transferFrom(address from, address to, uint256 tokenId) public virtual override;
265
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override;
266
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override;
267
}
268
```
269
270
### ERC721 Extensions
271
272
#### ERC721Burnable
273
274
Allows NFT burning.
275
276
```solidity { .api }
277
contract ERC721Burnable is Context, ERC721 {
278
function burn(uint256 tokenId) public virtual;
279
}
280
```
281
282
#### ERC721Enumerable
283
284
Adds enumeration capabilities to NFTs.
285
286
```solidity { .api }
287
contract ERC721Enumerable is ERC721, IERC721Enumerable {
288
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool);
289
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256);
290
function totalSupply() public view virtual override returns (uint256);
291
function tokenByIndex(uint256 index) public view virtual override returns (uint256);
292
}
293
```
294
295
#### ERC721Pausable
296
297
Pausable NFT transfers.
298
299
```solidity { .api }
300
contract ERC721Pausable is ERC721, Pausable {
301
// Inherits all ERC721 and Pausable functions
302
}
303
```
304
305
#### ERC721URIStorage
306
307
Per-token URI storage.
308
309
```solidity { .api }
310
contract ERC721URIStorage is ERC721 {
311
function tokenURI(uint256 tokenId) public view virtual override returns (string memory);
312
}
313
```
314
315
#### ERC721Votes
316
317
NFT with voting capabilities.
318
319
```solidity { .api }
320
contract ERC721Votes is ERC721, Votes {
321
function getVotes(address account) public view virtual override returns (uint256);
322
function getPastVotes(address account, uint256 blockNumber) public view virtual override returns (uint256);
323
function getPastTotalSupply(uint256 blockNumber) public view virtual override returns (uint256);
324
function delegates(address account) public view virtual override returns (address);
325
function delegate(address delegatee) public virtual override;
326
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) public virtual override;
327
}
328
```
329
330
#### ERC721Royalty
331
332
NFT with EIP2981 royalty support.
333
334
```solidity { .api }
335
contract ERC721Royalty is ERC721, ERC2981 {
336
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, ERC2981) returns (bool);
337
}
338
```
339
340
#### ERC721Consecutive
341
342
Batch minting of consecutive NFTs.
343
344
```solidity { .api }
345
abstract contract ERC721Consecutive is ERC721 {
346
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool);
347
function ownerOf(uint256 tokenId) public view virtual override returns (address);
348
}
349
```
350
351
**Events:**
352
- `ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed fromAddress, address indexed toAddress)`
353
354
### ERC721 Utilities
355
356
#### ERC721Holder
357
358
Safe NFT receiver contract.
359
360
```solidity { .api }
361
contract ERC721Holder is IERC721Receiver {
362
function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4);
363
}
364
```
365
366
### ERC721 Presets
367
368
#### ERC721PresetMinterPauserAutoId
369
370
NFT with auto-incrementing IDs, minting and pausing.
371
372
```solidity { .api }
373
contract ERC721PresetMinterPauserAutoId is Context, AccessControlEnumerable, ERC721Burnable, ERC721Pausable {
374
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
375
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
376
377
constructor(string memory name, string memory symbol, string memory baseTokenURI);
378
379
function mint(address to) public virtual;
380
function pause() public virtual;
381
function unpause() public virtual;
382
}
383
```
384
385
## ERC1155 Multi-Token Standard
386
387
### Core ERC1155 Implementation
388
389
```solidity { .api }
390
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
391
constructor(string memory uri_);
392
393
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);
394
function uri(uint256) public view virtual override returns (string memory);
395
function balanceOf(address account, uint256 id) public view virtual override returns (uint256);
396
function balanceOfBatch(address[] memory accounts, uint256[] memory ids) public view virtual override returns (uint256[] memory);
397
function setApprovalForAll(address operator, bool approved) public virtual override;
398
function isApprovedForAll(address account, address operator) public view virtual override returns (bool);
399
function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes memory data) public virtual override;
400
function safeBatchTransferFrom(address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public virtual override;
401
}
402
```
403
404
### ERC1155 Extensions
405
406
#### ERC1155Burnable
407
408
Allows multi-token burning.
409
410
```solidity { .api }
411
contract ERC1155Burnable is ERC1155 {
412
function burn(address account, uint256 id, uint256 value) public virtual;
413
function burnBatch(address account, uint256[] memory ids, uint256[] memory values) public virtual;
414
}
415
```
416
417
#### ERC1155Pausable
418
419
Pausable multi-token transfers.
420
421
```solidity { .api }
422
contract ERC1155Pausable is ERC1155, Pausable {
423
// Inherits all ERC1155 and Pausable functions
424
}
425
```
426
427
#### ERC1155Supply
428
429
Supply tracking for multi-tokens.
430
431
```solidity { .api }
432
contract ERC1155Supply is ERC1155 {
433
function totalSupply(uint256 id) public view virtual returns (uint256);
434
function exists(uint256 id) public view virtual returns (bool);
435
}
436
```
437
438
#### ERC1155URIStorage
439
440
Per-token URI storage for multi-tokens.
441
442
```solidity { .api }
443
contract ERC1155URIStorage is ERC1155 {
444
function uri(uint256 tokenId) public view virtual override returns (string memory);
445
}
446
```
447
448
### ERC1155 Utilities
449
450
#### ERC1155Holder
451
452
Safe multi-token receiver contract.
453
454
```solidity { .api }
455
contract ERC1155Holder is ERC1155Receiver {
456
function onERC1155Received(address, address, uint256, uint256, bytes memory) public virtual override returns (bytes4);
457
function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory) public virtual override returns (bytes4);
458
}
459
```
460
461
### ERC1155 Presets
462
463
#### ERC1155PresetMinterPauser
464
465
Multi-token with minting and pausing.
466
467
```solidity { .api }
468
contract ERC1155PresetMinterPauser is Context, AccessControlEnumerable, ERC1155Burnable, ERC1155Pausable {
469
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
470
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
471
472
constructor(string memory uri);
473
474
function mint(address to, uint256 id, uint256 amount, bytes memory data) public virtual;
475
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public virtual;
476
function pause() public virtual;
477
function unpause() public virtual;
478
}
479
```
480
481
## ERC777 Advanced Token Standard
482
483
### Core ERC777 Implementation
484
485
```solidity { .api }
486
contract ERC777 is Context, IERC777, IERC20 {
487
constructor(string memory name_, string memory symbol_, address[] memory defaultOperators_);
488
489
function name() public view virtual override returns (string memory);
490
function symbol() public view virtual override returns (string memory);
491
function decimals() public pure virtual returns (uint8);
492
function granularity() public view virtual override returns (uint256);
493
function totalSupply() public view virtual override(IERC20, IERC777) returns (uint256);
494
function balanceOf(address tokenHolder) public view virtual override(IERC20, IERC777) returns (uint256 balance);
495
function send(address recipient, uint256 amount, bytes memory data) public virtual override;
496
function burn(uint256 amount, bytes memory data) public virtual override;
497
function isOperatorFor(address operator, address tokenHolder) public view virtual override returns (bool);
498
function authorizeOperator(address operator) public virtual override;
499
function revokeOperator(address operator) public virtual override;
500
function defaultOperators() public view virtual override returns (address[] memory);
501
function operatorSend(address sender, address recipient, uint256 amount, bytes memory data, bytes memory operatorData) public virtual override;
502
function operatorBurn(address account, uint256 amount, bytes memory data, bytes memory operatorData) public virtual override;
503
function allowance(address holder, address spender) public view virtual override returns (uint256);
504
function approve(address spender, uint256 value) public virtual override returns (bool);
505
function transfer(address to, uint256 value) public virtual override returns (bool);
506
function transferFrom(address from, address to, uint256 value) public virtual override returns (bool);
507
}
508
```
509
510
**Events:**
511
- `Sent(address indexed operator, address indexed from, address indexed to, uint256 amount, bytes data, bytes operatorData)`
512
- `Minted(address indexed operator, address indexed to, uint256 amount, bytes data, bytes operatorData)`
513
- `Burned(address indexed operator, address indexed from, uint256 amount, bytes data, bytes operatorData)`
514
- `AuthorizedOperator(address indexed operator, address indexed holder)`
515
- `RevokedOperator(address indexed operator, address indexed holder)`
516
517
### ERC777 Presets
518
519
#### ERC777PresetFixedSupply
520
521
ERC777 token with fixed supply.
522
523
```solidity { .api }
524
contract ERC777PresetFixedSupply is ERC777 {
525
constructor(string memory name, string memory symbol, address[] memory defaultOperators, uint256 initialSupply, address owner);
526
}
527
```
528
529
## Common Token Features
530
531
### ERC2981 Royalty Standard
532
533
```solidity { .api }
534
abstract contract ERC2981 is IERC2981, ERC165 {
535
struct RoyaltyInfo {
536
address receiver;
537
uint96 royaltyFraction;
538
}
539
540
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool);
541
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) public view virtual override returns (address, uint256);
542
}
543
```
544
545
**Events:**
546
- `RoyaltySet(uint256 indexed tokenId, address indexed recipient, uint256 amount)`