Presets
Outdated Version
This document is better viewed at https://docs.openzeppelin.com/contracts/api/presets
These contracts integrate different Ethereum standards (ERCs) with custom extensions and modules, showcasing common configurations that are ready to deploy without having to write any Solidity code.
They can be used as-is for quick prototyping and testing, but are also suitable for production environments.
Intermediate and advanced users can use these as starting points when writing their own contracts, extending them with custom functionality as they see fit.
Tokens
ERC20PresetMinterPauser
ERC20 token, including:
- ability for holders to burn (destroy) their tokens
- a minter role that allows for token minting (creation)
- a pauser role that allows to stop all token transfers
This contract uses AccessControl to lock permissioned functions using the different roles - head to its documentation for details.
The account that deploys the contract will be granted the minter and pauser roles, as well as the default admin role, which will let it grant both minter and pauser roles to other accounts.
Functions
Pausable
ERC20Burnable
ERC20
name()
symbol()
decimals()
totalSupply()
balanceOf(account)
transfer(recipient, amount)
allowance(owner, spender)
approve(spender, amount)
transferFrom(sender, recipient, amount)
increaseAllowance(spender, addedValue)
decreaseAllowance(spender, subtractedValue)
_transfer(sender, recipient, amount)
_mint(account, amount)
_burn(account, amount)
_approve(owner, spender, amount)
_setupDecimals(decimals_)
AccessControl
hasRole(role, account)
getRoleMemberCount(role)
getRoleMember(role, index)
getRoleAdmin(role)
grantRole(role, account)
revokeRole(role, account)
renounceRole(role, account)
_setupRole(role, account)
_setRoleAdmin(role, adminRole)
Events
Pausable
IERC20
AccessControl
RoleAdminChanged(role, previousAdminRole, newAdminRole)
RoleGranted(role, account, sender)
RoleRevoked(role, account, sender)
constructor(string name, string symbol) *public*
Grants DEFAULT_ADMIN_ROLE
, MINTER_ROLE
and PAUSER_ROLE
to the
account that deploys the contract.
See ERC20-constructor.
mint(address to, uint256 amount) *public*
Creates amount
new tokens for to
.
See ERC20-_mint.
Requirements:
- the caller must have the
MINTER_ROLE
.
`pause() public
Pauses all token transfers.
See ERC20Pausable and Pausable-_pause.
Requirements:
*the caller must have the
PAUSER_ROLE`.
`unpause() public
Unpauses all token transfers.
See ERC20Pausable and Pausable-_unpause.
Requirements:
*the caller must have the
PAUSER_ROLE`.
_beforeTokenTransfer(address from, address to, uint256 amount) *internal*
ERC721PresetMinterPauserAutoId
ERC721 token, including:
- ability for holders to burn (destroy) their tokens
- a minter role that allows for token minting (creation)
- a pauser role that allows to stop all token transfers
- token ID and URI autogeneration
This contract uses AccessControl to lock permissioned functions using the different roles - head to its documentation for details.
The account that deploys the contract will be granted the minter and pauser roles, as well as the default admin role, which will let it grant both minter and pauser roles to other accounts.
Functions
constructor(name, symbol, baseURI)
mint(to)
pause()
unpause()
_beforeTokenTransfer(from, to, tokenId)
Pausable
ERC721Burnable
ERC721
balanceOf(owner)
ownerOf(tokenId)
name()
symbol()
tokenURI(tokenId)
baseURI()
tokenOfOwnerByIndex(owner, index)
totalSupply()
tokenByIndex(index)
approve(to, tokenId)
getApproved(tokenId)
setApprovalForAll(operator, approved)
isApprovedForAll(owner, operator)
transferFrom(from, to, tokenId)
safeTransferFrom(from, to, tokenId)
safeTransferFrom(from, to, tokenId, _data)
_safeTransfer(from, to, tokenId, _data)
_exists(tokenId)
_isApprovedOrOwner(spender, tokenId)
_safeMint(to, tokenId)
_safeMint(to, tokenId, _data)
_mint(to, tokenId)
_burn(tokenId)
_transfer(from, to, tokenId)
_setTokenURI(tokenId, _tokenURI)
_setBaseURI(baseURI_)
_approve(to, tokenId)
ERC165
AccessControl
hasRole(role, account)
getRoleMemberCount(role)
getRoleMember(role, index)
getRoleAdmin(role)
grantRole(role, account)
revokeRole(role, account)
renounceRole(role, account)
_setupRole(role, account)
_setRoleAdmin(role, adminRole)
Events
Pausable
IERC721
Transfer(from, to, tokenId)
Approval(owner, approved, tokenId)
ApprovalForAll(owner, operator, approved)
AccessControl
RoleAdminChanged(role, previousAdminRole, newAdminRole)
RoleGranted(role, account, sender)
RoleRevoked(role, account, sender)
constructor(string name, string symbol, string baseURI) *public*
Grants DEFAULT_ADMIN_ROLE
, MINTER_ROLE
and PAUSER_ROLE
to the
account that deploys the contract.
Token URIs will be autogenerated based on baseURI
and their token IDs.
See ERC721-tokenURI.
mint(address to) *public*
Creates a new token for to
. Its token ID will be automatically
assigned (and available on the emitted IERC721-Transfer event), and the token
URI autogenerated based on the base URI passed at construction.
See ERC721-_mint.
Requirements:
- the caller must have the
MINTER_ROLE
.
`pause() public
Pauses all token transfers.
See ERC721Pausable and Pausable-_pause.
Requirements:
*the caller must have the
PAUSER_ROLE`.
`unpause() public
Unpauses all token transfers.
See ERC721Pausable and Pausable-_unpause.
Requirements:
*the caller must have the
PAUSER_ROLE`.
_beforeTokenTransfer(address from, address to, uint256 tokenId) *internal*
ERC1155PresetMinterPauser
ERC1155 token, including:
- ability for holders to burn (destroy) their tokens
- a minter role that allows for token minting (creation)
- a pauser role that allows to stop all token transfers
This contract uses AccessControl to lock permissioned functions using the different roles - head to its documentation for details.
The account that deploys the contract will be granted the minter and pauser roles, as well as the default admin role, which will let it grant both minter and pauser roles to other accounts.
Functions
constructor(uri)
mint(to, id, amount, data)
mintBatch(to, ids, amounts, data)
pause()
unpause()
_beforeTokenTransfer(operator, from, to, ids, amounts, data)
Pausable
ERC1155Burnable
ERC1155
uri(_)
balanceOf(account, id)
balanceOfBatch(accounts, ids)
setApprovalForAll(operator, approved)
isApprovedForAll(account, operator)
safeTransferFrom(from, to, id, amount, data)
safeBatchTransferFrom(from, to, ids, amounts, data)
_setURI(newuri)
_mint(account, id, amount, data)
_mintBatch(to, ids, amounts, data)
_burn(account, id, amount)
_burnBatch(account, ids, amounts)
ERC165
AccessControl
hasRole(role, account)
getRoleMemberCount(role)
getRoleMember(role, index)
getRoleAdmin(role)
grantRole(role, account)
revokeRole(role, account)
renounceRole(role, account)
_setupRole(role, account)
_setRoleAdmin(role, adminRole)
Events
Pausable
IERC1155
TransferSingle(operator, from, to, id, value)
TransferBatch(operator, from, to, ids, values)
ApprovalForAll(account, operator, approved)
URI(value, id)
AccessControl
RoleAdminChanged(role, previousAdminRole, newAdminRole)
RoleGranted(role, account, sender)
RoleRevoked(role, account, sender)
constructor(string uri) *public*
Grants DEFAULT_ADMIN_ROLE
, MINTER_ROLE
, and PAUSER_ROLE
to the account that
deploys the contract.
mint(address to, uint256 id, uint256 amount, bytes data) *public*
Creates amount
new tokens for to
, of token type id
.
See ERC1155-_mint.
Requirements:
- the caller must have the
MINTER_ROLE
.
mintBatch(address to, uint256[] ids, uint256[] amounts, bytes data) *public*
Batched variant of mint.
`pause() public
Pauses all token transfers.
See ERC1155Pausable and Pausable-_pause.
Requirements:
*the caller must have the
PAUSER_ROLE`.
`unpause() public
Unpauses all token transfers.
See ERC1155Pausable and Pausable-_unpause.
Requirements:
*the caller must have the
PAUSER_ROLE`.
_beforeTokenTransfer(address operator, address from, address to, uint256[] ids, uint256[] amounts, bytes data) *internal*
ERC20PresetFixedSupply
ERC20 token, including:
- Preminted initial supply
- Ability for holders to burn (destroy) their tokens
- No access control mechanism (for minting/pausing) and hence no governance
This contract uses ERC20Burnable to include burn capabilities - head to its documentation for details.
Available since v3.4.
Functions
ERC20Burnable
ERC20
name()
symbol()
decimals()
totalSupply()
balanceOf(account)
transfer(recipient, amount)
allowance(owner, spender)
approve(spender, amount)
transferFrom(sender, recipient, amount)
increaseAllowance(spender, addedValue)
decreaseAllowance(spender, subtractedValue)
_transfer(sender, recipient, amount)
_mint(account, amount)
_burn(account, amount)
_approve(owner, spender, amount)
_setupDecimals(decimals_)
_beforeTokenTransfer(from, to, amount)
Events
IERC20
constructor(string name, string symbol, uint256 initialSupply, address owner) *public*
Mints initialSupply
amount of token and transfers them to owner
.
See ERC20-constructor.
ERC777PresetFixedSupply
ERC777 token, including:
- Preminted initial supply
- No access control mechanism (for minting/pausing) and hence no governance
Available since v3.4.
Functions
ERC777
name()
symbol()
decimals()
granularity()
totalSupply()
balanceOf(tokenHolder)
send(recipient, amount, data)
transfer(recipient, amount)
burn(amount, data)
isOperatorFor(operator, tokenHolder)
authorizeOperator(operator)
revokeOperator(operator)
defaultOperators()
operatorSend(sender, recipient, amount, data, operatorData)
operatorBurn(account, amount, data, operatorData)
allowance(holder, spender)
approve(spender, value)
transferFrom(holder, recipient, amount)
_mint(account, amount, userData, operatorData)
_send(from, to, amount, userData, operatorData, requireReceptionAck)
_burn(from, amount, data, operatorData)
_approve(holder, spender, value)
_beforeTokenTransfer(operator, from, to, amount)
Events
IERC20
IERC777
Sent(operator, from, to, amount, data, operatorData)
Minted(operator, to, amount, data, operatorData)
Burned(operator, from, amount, data, operatorData)
AuthorizedOperator(operator, tokenHolder)
RevokedOperator(operator, tokenHolder)
constructor(string name, string symbol, address[] defaultOperators, uint256 initialSupply, address owner) *public*
Mints initialSupply
amount of token and transfers them to owner
.
See ERC777-constructor.