Presets

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.

constructor(string name, string symbol) public

Grants DEFAULT_ADMIN_ROLE, MINTER_ROLE and PAUSER_ROLE to the account that deploys the contract.

mint(address to, uint256 amount) public

Creates amount new tokens for to.

Requirements:

  • the caller must have the MINTER_ROLE.

pause() public

Pauses all token transfers.

Requirements:

  • the caller must have the PAUSER_ROLE.

unpause() public

Unpauses all token transfers.

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.

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.

Requirements:

  • the caller must have the MINTER_ROLE.

pause() public

Pauses all token transfers.

Requirements:

  • the caller must have the PAUSER_ROLE.

unpause() public

Unpauses all token transfers.

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.

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.

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.

Requirements:

  • the caller must have the PAUSER_ROLE.

unpause() public

Unpauses all token transfers.

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.

constructor(string name, string symbol, uint256 initialSupply, address owner) public

Mints initialSupply amount of token and transfers them to owner.