Interfaces
Smart contract interfaces utilities and implementations
List of standardized interfaces
These interfaces are available as .sol
files, and also as compiler .json
ABI files (through the npm package). These
are useful to interact with third party contracts that implement them.
IERC20
IERC20Errors
IERC20Metadata
IERC165
IERC721
IERC721Receiver
IERC721Enumerable
IERC721Metadata
IERC721Errors
IERC777
IERC777Recipient
IERC777Sender
IERC1155
IERC1155Receiver
IERC1155MetadataURI
IERC1155Errors
IERC1271
IERC1363
IERC1363Receiver
IERC1363Spender
IERC1820Implementer
IERC1820Registry
IERC1822Proxiable
IERC2612
IERC2981
IERC3156FlashLender
IERC3156FlashBorrower
IERC4626
IERC4906
IERC5267
IERC5313
IERC5805
IERC6372
IERC6909
IERC6909ContentURI
IERC6909Metadata
IERC6909TokenSupply
IERC7674
IERC7786GatewaySource
IERC7802
Detailed ABI
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
Interface of the ERC-1271 standard signature validation method for contracts as defined in ERC-1271.
Functions
isValidSignature(bytes32 hash, bytes signature) → bytes4 magicValue
external
#Should return whether the signature provided is valid for the provided data
import "@openzeppelin/contracts/interfaces/IERC1363.sol";
Interface of the ERC-1363 standard as defined in the ERC-1363.
Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
after transfer
or transferFrom
, or code on a spender contract after approve
, in a single transaction.
Functions
transferAndCall(address to, uint256 value) → bool
external
#Moves a value
amount of tokens from the caller's account to to
and then calls IERC1363Receiver.onTransferReceived
on to
.
transferAndCall(address to, uint256 value, bytes data) → bool
external
#Moves a value
amount of tokens from the caller's account to to
and then calls IERC1363Receiver.onTransferReceived
on to
.
transferFromAndCall(address from, address to, uint256 value) → bool
external
#Moves a value
amount of tokens from from
to to
using the allowance mechanism
and then calls IERC1363Receiver.onTransferReceived
on to
.
transferFromAndCall(address from, address to, uint256 value, bytes data) → bool
external
#Moves a value
amount of tokens from from
to to
using the allowance mechanism
and then calls IERC1363Receiver.onTransferReceived
on to
.
approveAndCall(address spender, uint256 value) → bool
external
#Sets a value
amount of tokens as the allowance of spender
over the
caller's tokens and then calls IERC1363Spender.onApprovalReceived
on spender
.
approveAndCall(address spender, uint256 value, bytes data) → bool
external
#Sets a value
amount of tokens as the allowance of spender
over the
caller's tokens and then calls IERC1363Spender.onApprovalReceived
on spender
.
import "@openzeppelin/contracts/interfaces/IERC1363Receiver.sol";
Interface for any contract that wants to support transferAndCall
or transferFromAndCall
from ERC-1363 token contracts.
onTransferReceived(address operator, address from, uint256 value, bytes data) → bytes4
external
#Whenever ERC-1363 tokens are transferred to this contract via transferAndCall
or transferFromAndCall
by operator
from from
, this function is called.
NOTE: To accept the transfer, this must return
bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)"))
(i.e. 0x88a7ca5c, or its own function selector).
import "@openzeppelin/contracts/interfaces/IERC1363Spender.sol";
Interface for any contract that wants to support approveAndCall
from ERC-1363 token contracts.
Functions
onApprovalReceived(address owner, uint256 value, bytes data) → bytes4
external
#Whenever an ERC-1363 token owner
approves this contract via approveAndCall
to spend their tokens, this function is called.
NOTE: To accept the approval, this must return
bytes4(keccak256("onApprovalReceived(address,uint256,bytes)"))
(i.e. 0x7b04a2d0, or its own function selector).
import "@openzeppelin/contracts/interfaces/IERC1820Implementer.sol";
Interface for an ERC-1820 implementer, as defined in the
ERC.
Used by contracts that will be registered as implementers in the
IERC1820Registry
.
canImplementInterfaceForAddress(bytes32 interfaceHash, address account) → bytes32
external
#Returns a special value (ERC1820_ACCEPT_MAGIC
) if this contract
implements interfaceHash
for account
.
import "@openzeppelin/contracts/interfaces/IERC1820Registry.sol";
Interface of the global ERC-1820 Registry, as defined in the ERC. Accounts may register implementers for interfaces in this registry, as well as query support.
Implementers may be shared by multiple accounts, and can also implement more than a single interface for each account. Contracts can implement interfaces for themselves, but externally-owned accounts (EOA) must delegate this to a contract.
IERC165
interfaces can also be queried via the registry.
For an in-depth explanation and source code analysis, see the ERC text.
Functions
- setManager(account, newManager)
- getManager(account)
- setInterfaceImplementer(account, _interfaceHash, implementer)
- getInterfaceImplementer(account, _interfaceHash)
- interfaceHash(interfaceName)
- updateERC165Cache(account, interfaceId)
- implementsERC165Interface(account, interfaceId)
- implementsERC165InterfaceNoCache(account, interfaceId)
Events
setManager(address account, address newManager)
external
#Sets newManager
as the manager for account
. A manager of an
account is able to set interface implementers for it.
By default, each account is its own manager. Passing a value of 0x0
in
newManager
will reset the manager to this initial state.
Emits a IERC1820Registry.ManagerChanged
event.
Requirements:
- the caller must be the current manager for
account
.
getManager(address account) → address
external
#Returns the manager for account
.
setInterfaceImplementer(address account, bytes32 _interfaceHash, address implementer)
external
#Sets the implementer
contract as account
's implementer for
interfaceHash
.
account
being the zero address is an alias for the caller's address.
The zero address can also be used in implementer
to remove an old one.
See IERC1820Registry.interfaceHash
to learn how these are created.
Emits an IERC1820Registry.InterfaceImplementerSet
event.
Requirements:
- the caller must be the current manager for
account
. interfaceHash
must not be anIERC165
interface id (i.e. it must not end in 28 zeroes).implementer
must implementIERC1820Implementer
and return true when queried for support, unlessimplementer
is the caller. SeeIERC1820Implementer.canImplementInterfaceForAddress
.
getInterfaceImplementer(address account, bytes32 _interfaceHash) → address
external
#Returns the implementer of interfaceHash
for account
. If no such
implementer is registered, returns the zero address.
If interfaceHash
is an IERC165
interface id (i.e. it ends with 28
zeroes), account
will be queried for support of it.
account
being the zero address is an alias for the caller's address.
interfaceHash(string interfaceName) → bytes32
external
#Returns the interface hash for an interfaceName
, as defined in the
corresponding
section of the ERC.
updateERC165Cache(address account, bytes4 interfaceId)
external
#implementsERC165Interface(address account, bytes4 interfaceId) → bool
external
#implementsERC165InterfaceNoCache(address account, bytes4 interfaceId) → bool
external
#InterfaceImplementerSet(address indexed account, bytes32 indexed interfaceHash, address indexed implementer)
event
#ManagerChanged(address indexed account, address indexed newManager)
event
#import "@openzeppelin/contracts/interfaces/IERC1967.sol";
ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
Upgraded(address indexed implementation)
event
#Emitted when the implementation is upgraded.
AdminChanged(address previousAdmin, address newAdmin)
event
#Emitted when the admin account has changed.
BeaconUpgraded(address indexed beacon)
event
#Emitted when the beacon is changed.
import "@openzeppelin/contracts/interfaces/IERC2309.sol";
ERC-2309: ERC-721 Consecutive Transfer Extension.
ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed fromAddress, address indexed toAddress)
event
#Emitted when the tokens from fromTokenId
to toTokenId
are transferred from fromAddress
to toAddress
.
import "@openzeppelin/contracts/interfaces/IERC2612.sol";
Functions
import "@openzeppelin/contracts/interfaces/IERC2981.sol";
Interface for the NFT Royalty Standard.
A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal support for royalty payments across all NFT marketplaces and ecosystem participants.
royaltyInfo(uint256 tokenId, uint256 salePrice) → address receiver, uint256 royaltyAmount
external
#Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of exchange. The royalty amount is denominated and should be paid in that same unit of exchange.
NOTE: ERC-2981 allows setting the royalty to 100% of the price. In that case all the price would be sent to the royalty receiver and 0 tokens to the seller. Contracts dealing with royalty should consider empty transfers.
import "@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol";
Interface of the ERC-3156 FlashBorrower, as defined in ERC-3156.
onFlashLoan(address initiator, address token, uint256 amount, uint256 fee, bytes data) → bytes32
external
#Receive a flash loan.
import "@openzeppelin/contracts/interfaces/IERC3156FlashLender.sol";
Interface of the ERC-3156 FlashLender, as defined in ERC-3156.
maxFlashLoan(address token) → uint256
external
#The amount of currency available to be lended.
flashFee(address token, uint256 amount) → uint256
external
#The fee to be charged for a given loan.
flashLoan(contract IERC3156FlashBorrower receiver, address token, uint256 amount, bytes data) → bool
external
#Initiate a flash loan.
import "@openzeppelin/contracts/interfaces/IERC4626.sol";
Interface of the ERC-4626 "Tokenized Vault Standard", as defined in ERC-4626.
Functions
- asset()
- totalAssets()
- convertToShares(assets)
- convertToAssets(shares)
- maxDeposit(receiver)
- previewDeposit(assets)
- deposit(assets, receiver)
- maxMint(receiver)
- previewMint(shares)
- mint(shares, receiver)
- maxWithdraw(owner)
- previewWithdraw(assets)
- withdraw(assets, receiver, owner)
- maxRedeem(owner)
- previewRedeem(shares)
- redeem(shares, receiver, owner)
IERC20Metadata
IERC20
Events
asset() → address assetTokenAddress
external
#Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
- MUST be an ERC-20 token contract.
- MUST NOT revert.
totalAssets() → uint256 totalManagedAssets
external
#Returns the total amount of the underlying asset that is “managed” by Vault.
- SHOULD include any compounding that occurs from yield.
- MUST be inclusive of any fees that are charged against assets in the Vault.
- MUST NOT revert.
convertToShares(uint256 assets) → uint256 shares
external
#Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal scenario where all the conditions are met.
- MUST NOT be inclusive of any fees that are charged against assets in the Vault.
- MUST NOT show any variations depending on the caller.
- MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
- MUST NOT revert.
NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and from.
convertToAssets(uint256 shares) → uint256 assets
external
#Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal scenario where all the conditions are met.
- MUST NOT be inclusive of any fees that are charged against assets in the Vault.
- MUST NOT show any variations depending on the caller.
- MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
- MUST NOT revert.
NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and from.
maxDeposit(address receiver) → uint256 maxAssets
external
#Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver, through a deposit call.
- MUST return a limited value if receiver is subject to some deposit limit.
- MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
- MUST NOT revert.
previewDeposit(uint256 assets) → uint256 shares
external
#Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given current on-chain conditions.
- MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called in the same transaction.
- MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the deposit would be accepted, regardless if the user has enough tokens approved, etc.
- MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
- MUST NOT revert.
NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in share price or some other type of condition, meaning the depositor will lose assets by depositing.
deposit(uint256 assets, address receiver) → uint256 shares
external
#Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
- MUST emit the Deposit event.
- MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the deposit execution, and are accounted for during deposit.
- MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not approving enough underlying tokens to the Vault contract, etc).
NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
maxMint(address receiver) → uint256 maxShares
external
#Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
- MUST return a limited value if receiver is subject to some mint limit.
- MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
- MUST NOT revert.
previewMint(uint256 shares) → uint256 assets
external
#Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given current on-chain conditions.
- MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the same transaction.
- MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint would be accepted, regardless if the user has enough tokens approved, etc.
- MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
- MUST NOT revert.
NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in share price or some other type of condition, meaning the depositor will lose assets by minting.
mint(uint256 shares, address receiver) → uint256 assets
external
#Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
- MUST emit the Deposit event.
- MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint execution, and are accounted for during mint.
- MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not approving enough underlying tokens to the Vault contract, etc).
NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
maxWithdraw(address owner) → uint256 maxAssets
external
#Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the Vault, through a withdraw call.
- MUST return a limited value if owner is subject to some withdrawal limit or timelock.
- MUST NOT revert.
previewWithdraw(uint256 assets) → uint256 shares
external
#Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block, given current on-chain conditions.
- MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if called in the same transaction.
- MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though the withdrawal would be accepted, regardless if the user has enough shares, etc.
- MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
- MUST NOT revert.
NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in share price or some other type of condition, meaning the depositor will lose assets by depositing.
withdraw(uint256 assets, address receiver, address owner) → uint256 shares
external
#Burns shares from owner and sends exactly assets of underlying tokens to receiver.
- MUST emit the Withdraw event.
- MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the withdraw execution, and are accounted for during withdraw.
- MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner not having enough shares, etc).
Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed. Those methods should be performed separately.
maxRedeem(address owner) → uint256 maxShares
external
#Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault, through a redeem call.
- MUST return a limited value if owner is subject to some withdrawal limit or timelock.
- MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
- MUST NOT revert.
previewRedeem(uint256 shares) → uint256 assets
external
#Allows an on-chain or off-chain user to simulate the effects of their redemption at the current block, given current on-chain conditions.
- MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the same transaction.
- MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the redemption would be accepted, regardless if the user has enough shares, etc.
- MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
- MUST NOT revert.
NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in share price or some other type of condition, meaning the depositor will lose assets by redeeming.
redeem(uint256 shares, address receiver, address owner) → uint256 assets
external
#Burns exactly shares from owner and sends assets of underlying tokens to receiver.
- MUST emit the Withdraw event.
- MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the redeem execution, and are accounted for during redeem.
- MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner not having enough shares, etc).
NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed. Those methods should be performed separately.
Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares)
event
#Withdraw(address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares)
event
#import "@openzeppelin/contracts/interfaces/IERC4906.sol";
Functions
Events
MetadataUpdate(uint256 _tokenId)
event
#This event emits when the metadata of a token is changed. So that the third-party platforms such as NFT market could timely update the images and related attributes of the NFT.
BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId)
event
#This event emits when the metadata of a range of tokens is changed. So that the third-party platforms such as NFT market could timely update the images and related attributes of the NFTs.
import "@openzeppelin/contracts/interfaces/IERC5267.sol";
Functions
Events
eip712Domain() → bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions
external
#returns the fields and values that describe the domain separator used by this contract for EIP-712 signature.
EIP712DomainChanged()
event
#MAY be emitted to signal that the domain could have changed.
import "@openzeppelin/contracts/interfaces/IERC5313.sol";
Interface for the Light Contract Ownership Standard.
A standardized minimal interface required to identify an account that controls a contract
Functions
owner() → address
external
#Gets the address of the owner.
import "@openzeppelin/contracts/interfaces/IERC5805.sol";
Functions
Events
import "@openzeppelin/contracts/interfaces/IERC6372.sol";
Functions
clock() → uint48
external
#Clock used for flagging checkpoints. Can be overridden to implement timestamp based checkpoints (and voting).
CLOCK_MODE() → string
external
#Description of the clock
import "@openzeppelin/contracts/interfaces/IERC777.sol";
Interface of the ERC-777 Token standard as defined in the ERC.
This contract uses the
ERC-1820 registry standard to let
token holders and recipients react to token movements by using setting implementers
for the associated interfaces in said registry. See IERC1820Registry
and
IERC1820Implementer
.
Functions
- name()
- symbol()
- granularity()
- totalSupply()
- balanceOf(owner)
- send(recipient, amount, data)
- burn(amount, data)
- isOperatorFor(operator, tokenHolder)
- authorizeOperator(operator)
- revokeOperator(operator)
- defaultOperators()
- operatorSend(sender, recipient, amount, data, operatorData)
- operatorBurn(account, amount, data, operatorData)
Events
name() → string
external
#Returns the name of the token.
symbol() → string
external
#Returns the symbol of the token, usually a shorter version of the name.
granularity() → uint256
external
#Returns the smallest part of the token that is not divisible. This means all token operations (creation, movement and destruction) must have amounts that are a multiple of this number.
For most token contracts, this value will equal 1.
totalSupply() → uint256
external
#Returns the amount of tokens in existence.
balanceOf(address owner) → uint256
external
#Returns the amount of tokens owned by an account (owner
).
send(address recipient, uint256 amount, bytes data)
external
#Moves amount
tokens from the caller's account to recipient
.
If send or receive hooks are registered for the caller and recipient
,
the corresponding functions will be called with data
and empty
operatorData
. See IERC777Sender
and IERC777Recipient
.
Emits a IERC777.Sent
event.
Requirements
- the caller must have at least
amount
tokens. recipient
cannot be the zero address.- if
recipient
is a contract, it must implement theIERC777Recipient
interface.
burn(uint256 amount, bytes data)
external
#Destroys amount
tokens from the caller's account, reducing the
total supply.
If a send hook is registered for the caller, the corresponding function
will be called with data
and empty operatorData
. See IERC777Sender
.
Emits a IERC777.Burned
event.
Requirements
- the caller must have at least
amount
tokens.
isOperatorFor(address operator, address tokenHolder) → bool
external
#Returns true if an account is an operator of tokenHolder
.
Operators can send and burn tokens on behalf of their owners. All
accounts are their own operator.
See IERC777.operatorSend
and IERC777.operatorBurn
.
authorizeOperator(address operator)
external
#Make an account an operator of the caller.
Emits an IERC777.AuthorizedOperator
event.
Requirements
operator
cannot be calling address.
revokeOperator(address operator)
external
#Revoke an account's operator status for the caller.
See IERC777.isOperatorFor
and IERC777.defaultOperators
.
Emits a IERC777.RevokedOperator
event.
Requirements
operator
cannot be calling address.
defaultOperators() → address[]
external
#Returns the list of default operators. These accounts are operators
for all token holders, even if IERC777.authorizeOperator
was never called on
them.
This list is immutable, but individual holders may revoke these via
IERC777.revokeOperator
, in which case IERC777.isOperatorFor
will return false.
operatorSend(address sender, address recipient, uint256 amount, bytes data, bytes operatorData)
external
#Moves amount
tokens from sender
to recipient
. The caller must
be an operator of sender
.
If send or receive hooks are registered for sender
and recipient
,
the corresponding functions will be called with data
and
operatorData
. See IERC777Sender
and IERC777Recipient
.
Emits a IERC777.Sent
event.
Requirements
sender
cannot be the zero address.sender
must have at leastamount
tokens.- the caller must be an operator for
sender
. recipient
cannot be the zero address.- if
recipient
is a contract, it must implement theIERC777Recipient
interface.
operatorBurn(address account, uint256 amount, bytes data, bytes operatorData)
external
#Destroys amount
tokens from account
, reducing the total supply.
The caller must be an operator of account
.
If a send hook is registered for account
, the corresponding function
will be called with data
and operatorData
. See IERC777Sender
.
Emits a IERC777.Burned
event.
Requirements
account
cannot be the zero address.account
must have at leastamount
tokens.- the caller must be an operator for
account
.
Minted(address indexed operator, address indexed to, uint256 amount, bytes data, bytes operatorData)
event
#Emitted when amount
tokens are created by operator
and assigned to to
.
Note that some additional user data
and operatorData
can be logged in the event.
Burned(address indexed operator, address indexed from, uint256 amount, bytes data, bytes operatorData)
event
#Emitted when operator
destroys amount
tokens from account
.
Note that some additional user data
and operatorData
can be logged in the event.
AuthorizedOperator(address indexed operator, address indexed tokenHolder)
event
#Emitted when operator
is made operator for tokenHolder
.
RevokedOperator(address indexed operator, address indexed tokenHolder)
event
#Emitted when operator
is revoked its operator status for tokenHolder
.
Sent(address indexed operator, address indexed from, address indexed to, uint256 amount, bytes data, bytes operatorData)
event
#import "@openzeppelin/contracts/interfaces/IERC777Recipient.sol";
Interface of the ERC-777 Tokens Recipient standard as defined in the ERC.
Accounts can be notified of IERC777
tokens being sent to them by having a
contract implement this interface (contract holders can be their own
implementer) and registering it on the
ERC-1820 global registry.
See IERC1820Registry
and IERC1820Implementer
.
tokensReceived(address operator, address from, address to, uint256 amount, bytes userData, bytes operatorData)
external
#Called by an IERC777
token contract whenever tokens are being
moved or created into a registered account (to
). The type of operation
is conveyed by from
being the zero address or not.
This call occurs after the token contract's state is updated, so
IERC777.balanceOf
, etc., can be used to query the post-operation state.
This function may revert to prevent the operation from being executed.
import "@openzeppelin/contracts/interfaces/IERC777Sender.sol";
Interface of the ERC-777 Tokens Sender standard as defined in the ERC.
IERC777
Token holders can be notified of operations performed on their
tokens by having a contract implement this interface (contract holders can be
their own implementer) and registering it on the
ERC-1820 global registry.
See IERC1820Registry
and IERC1820Implementer
.
tokensToSend(address operator, address from, address to, uint256 amount, bytes userData, bytes operatorData)
external
#Called by an IERC777
token contract whenever a registered holder's
(from
) tokens are about to be moved or destroyed. The type of operation
is conveyed by to
being the zero address or not.
This call occurs before the token contract's state is updated, so
IERC777.balanceOf
, etc., can be used to query the pre-operation state.
This function may revert to prevent the operation from being executed.
import "@openzeppelin/contracts/interfaces/IERC7913.sol";
Signature verifier interface.
Functions
verify(bytes key, bytes32 hash, bytes signature) → bytes4
external
#Verifies signature
as a valid signature of hash
by key
.
MUST return the bytes4 magic value IERC7913SignatureVerifier.verify.selector if the signature is valid. SHOULD return 0xffffffff or revert if the signature is not valid. SHOULD return 0xffffffff or revert if the key is empty
import "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified proxy whose upgrades are fully controlled by the current implementation.
Functions
proxiableUUID() → bytes32
external
#Returns the storage slot that the proxiable contract assumes is being used to store the implementation address.
A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this function revert if invoked through a proxy.
import "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
A user operation is composed of the following elements:
sender
(address
): The account making the operationnonce
(uint256
): Anti-replay parameter (see “Semi-abstracted Nonce Support” )factory
(address
): account factory, only for new accountsfactoryData
(bytes
): data for account factory (only if account factory exists)callData
(bytes
): The data to pass to the sender during the main execution callcallGasLimit
(uint256
): The amount of gas to allocate the main execution callverificationGasLimit
(uint256
): The amount of gas to allocate for the verification steppreVerificationGas
(uint256
): Extra gas to pay the bundlermaxFeePerGas
(uint256
): Maximum fee per gas (similar to EIP-1559 max_fee_per_gas)maxPriorityFeePerGas
(uint256
): Maximum priority fee per gas (similar to EIP-1559 max_priority_fee_per_gas)paymaster
(address
): Address of paymaster contract, (or empty, if account pays for itself)paymasterVerificationGasLimit
(uint256
): The amount of gas to allocate for the paymaster validation codepaymasterPostOpGasLimit
(uint256
): The amount of gas to allocate for the paymaster post-operation codepaymasterData
(bytes
): Data for paymaster (only if paymaster exists)signature
(bytes
): Data passed into the account to verify authorization
When passed to on-chain contracts, the following packed version is used.
sender
(address
)nonce
(uint256
)initCode
(bytes
): concatenation of factory address and factoryData (or empty)callData
(bytes
)accountGasLimits
(bytes32
): concatenation of verificationGas (16 bytes) and callGas (16 bytes)preVerificationGas
(uint256
)gasFees
(bytes32
): concatenation of maxPriorityFeePerGas (16 bytes) and maxFeePerGas (16 bytes)paymasterAndData
(bytes
): concatenation of paymaster fields (or empty)signature
(bytes
)
import "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
Aggregates and validates multiple signatures for a batch of user operations.
A contract could implement this interface with custom validation schemes that allow signature aggregation, enabling significant optimizations and gas savings for execution and transaction data cost.
Bundlers and clients whitelist supported aggregators.
See ERC-7766
Functions
validateUserOpSignature(struct PackedUserOperation userOp) → bytes sigForUserOp
external
#Validates the signature for a user operation. Returns an alternative signature that should be used during bundling.
aggregateSignatures(struct PackedUserOperation[] userOps) → bytes aggregatesSignature
external
#Returns an aggregated signature for a batch of user operation's signatures.
validateSignatures(struct PackedUserOperation[] userOps, bytes signature)
external
#Validates that the aggregated signature is valid for the user operations.
Requirements:
- The aggregated signature MUST match the given list of operations.
import "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
Handle nonce management for accounts.
Nonces are used in accounts as a replay protection mechanism and to ensure the order of user operations.
To avoid limiting the number of operations an account can perform, the interface allows using parallel
nonces by using a key
parameter.
See ERC-4337 semi-abstracted nonce support.
Functions
getNonce(address sender, uint192 key) → uint256 nonce
external
#Returns the nonce for a sender
account and a key
.
Nonces for a certain key
are always increasing.
import "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
Handle stake management for entities (i.e. accounts, paymasters, factories).
The EntryPoint must implement the following API to let entities like paymasters have a stake, and thus have more flexibility in their storage access (see reputation, throttling and banning.)
Functions
balanceOf(address account) → uint256
external
#Returns the balance of the account.
depositTo(address account)
external
#Deposits msg.value
to the account.
withdrawTo(address payable withdrawAddress, uint256 withdrawAmount)
external
#Withdraws withdrawAmount
from the account to withdrawAddress
.
addStake(uint32 unstakeDelaySec)
external
#Adds stake to the account with an unstake delay of unstakeDelaySec
.
unlockStake()
external
#Unlocks the stake of the account.
withdrawStake(address payable withdrawAddress)
external
#Withdraws the stake of the account to withdrawAddress
.
import "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
Entry point for user operations.
User operations are validated and executed by this contract.
Functions
Errors
handleOps(struct PackedUserOperation[] ops, address payable beneficiary)
external
#Executes a batch of user operations.
handleAggregatedOps(struct IEntryPoint.UserOpsPerAggregator[] opsPerAggregator, address payable beneficiary)
external
#Executes a batch of aggregated user operations per aggregator.
FailedOp(uint256 opIndex, string reason)
error
#A user operation at opIndex
failed with reason
.
FailedOpWithRevert(uint256 opIndex, string reason, bytes inner)
error
#A user operation at opIndex
failed with reason
and inner
returned data.
import "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
Base interface for an ERC-4337 account.
validateUserOp(struct PackedUserOperation userOp, bytes32 userOpHash, uint256 missingAccountFunds) → uint256 validationData
external
#Validates a user operation.
- MUST validate the caller is a trusted EntryPoint
- MUST validate that the signature is a valid signature of the userOpHash, and SHOULD return SIG_VALIDATION_FAILED (and not revert) on signature mismatch. Any other error MUST revert.
- MUST pay the entryPoint (caller) at least the “missingAccountFunds” (which might be zero, in case the current account’s deposit is high enough)
Returns an encoded packed validation data that is composed of the following elements:
authorizer
(address
): 0 for success, 1 for failure, otherwise the address of an authorizer contractvalidUntil
(uint48
): The UserOp is valid only up to this time. Zero for “infinite”.validAfter
(uint48
): The UserOp is valid only after this time.
import "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
Support for executing user operations by prepending the IAccountExecute.executeUserOp
function selector
to the UserOperation's callData
.
Functions
executeUserOp(struct PackedUserOperation userOp, bytes32 userOpHash)
external
#Executes a user operation.
import "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
Interface for a paymaster contract that agrees to pay for the gas costs of a user operation.
NOTE: A paymaster must hold a stake to cover the required entrypoint stake and also the gas for the transaction.
Functions
validatePaymasterUserOp(struct PackedUserOperation userOp, bytes32 userOpHash, uint256 maxCost) → bytes context, uint256 validationData
external
#Validates whether the paymaster is willing to pay for the user operation. See
IAccount.validateUserOp
for additional information on the return value.
NOTE: Bundlers will reject this method if it modifies the state, unless it's whitelisted.
postOp(enum IPaymaster.PostOpMode mode, bytes context, uint256 actualGasCost, uint256 actualUserOpFeePerGas)
external
#Verifies the sender is the entrypoint.
import "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
Standard ERC-20 Errors Interface of the ERC-6093 custom errors for ERC-20 tokens.
Errors
ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed)
error
#Indicates an error related to the current balance
of a sender
. Used in transfers.
ERC20InvalidSender(address sender)
error
#Indicates a failure with the token sender
. Used in transfers.
ERC20InvalidReceiver(address receiver)
error
#Indicates a failure with the token receiver
. Used in transfers.
ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed)
error
#Indicates a failure with the spender
’s allowance
. Used in transfers.
ERC20InvalidApprover(address approver)
error
#Indicates a failure with the approver
of a token to be approved. Used in approvals.
ERC20InvalidSpender(address spender)
error
#Indicates a failure with the spender
to be approved. Used in approvals.
import "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
Standard ERC-721 Errors Interface of the ERC-6093 custom errors for ERC-721 tokens.
Errors
ERC721InvalidOwner(address owner)
error
#Indicates that an address can't be an owner. For example, address(0)
is a forbidden owner in ERC-20.
Used in balance queries.
ERC721NonexistentToken(uint256 tokenId)
error
#Indicates a tokenId
whose owner
is the zero address.
ERC721IncorrectOwner(address sender, uint256 tokenId, address owner)
error
#Indicates an error related to the ownership over a particular token. Used in transfers.
ERC721InvalidSender(address sender)
error
#Indicates a failure with the token sender
. Used in transfers.
ERC721InvalidReceiver(address receiver)
error
#Indicates a failure with the token receiver
. Used in transfers.
ERC721InsufficientApproval(address operator, uint256 tokenId)
error
#Indicates a failure with the operator
’s approval. Used in transfers.
ERC721InvalidApprover(address approver)
error
#Indicates a failure with the approver
of a token to be approved. Used in approvals.
ERC721InvalidOperator(address operator)
error
#Indicates a failure with the operator
to be approved. Used in approvals.
import "@openzeppelin/contracts/interfaces/draft-IERC6093.sol";
Standard ERC-1155 Errors Interface of the ERC-6093 custom errors for ERC-1155 tokens.
Errors
ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId)
error
#Indicates an error related to the current balance
of a sender
. Used in transfers.
ERC1155InvalidSender(address sender)
error
#Indicates a failure with the token sender
. Used in transfers.
ERC1155InvalidReceiver(address receiver)
error
#Indicates a failure with the token receiver
. Used in transfers.
ERC1155MissingApprovalForAll(address operator, address owner)
error
#Indicates a failure with the operator
’s approval. Used in transfers.
ERC1155InvalidApprover(address approver)
error
#Indicates a failure with the approver
of a token to be approved. Used in approvals.
ERC1155InvalidOperator(address operator)
error
#Indicates a failure with the operator
to be approved. Used in approvals.
ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength)
error
#Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation. Used in batch transfers.
import "@openzeppelin/contracts/interfaces/draft-IERC6909.sol";
Required interface of an ERC-6909 compliant contract, as defined in the ERC.
Functions
Events
balanceOf(address owner, uint256 id) → uint256
external
#Returns the amount of tokens of type id
owned by owner
.
allowance(address owner, address spender, uint256 id) → uint256
external
#Returns the amount of tokens of type id
that spender
is allowed to spend on behalf of owner
.
NOTE: Does not include operator allowances.
isOperator(address owner, address spender) → bool
external
#Returns true if spender
is set as an operator for owner
.
approve(address spender, uint256 id, uint256 amount) → bool
external
#Sets an approval to spender
for amount
of tokens of type id
from the caller's tokens. An amount
of
type(uint256).max
signifies an unlimited approval.
Must return true.
setOperator(address spender, bool approved) → bool
external
#Grants or revokes unlimited transfer permission of any token id to spender
for the caller's tokens.
Must return true.
transfer(address receiver, uint256 id, uint256 amount) → bool
external
#Transfers amount
of token type id
from the caller's account to receiver
.
Must return true.
transferFrom(address sender, address receiver, uint256 id, uint256 amount) → bool
external
#Transfers amount
of token type id
from sender
to receiver
.
Must return true.
Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount)
event
#Emitted when the allowance of a spender
for an owner
is set for a token of type id
.
The new allowance is amount
.
OperatorSet(address indexed owner, address indexed spender, bool approved)
event
#Emitted when owner
grants or revokes operator status for a spender
.
Transfer(address caller, address indexed sender, address indexed receiver, uint256 indexed id, uint256 amount)
event
#Emitted when amount
tokens of type id
are moved from sender
to receiver
initiated by caller
.
import "@openzeppelin/contracts/interfaces/draft-IERC6909.sol";
Optional extension of IERC6909
that adds metadata functions.
Functions
Events
name(uint256 id) → string
external
#Returns the name of the token of type id
.
symbol(uint256 id) → string
external
#Returns the ticker symbol of the token of type id
.
decimals(uint256 id) → uint8
external
#Returns the number of decimals for the token of type id
.
import "@openzeppelin/contracts/interfaces/draft-IERC6909.sol";
Optional extension of IERC6909
that adds content URI functions.
Functions
Events
contractURI() → string
external
#Returns URI for the contract.
tokenURI(uint256 id) → string
external
#Returns the URI for the token of type id
.
import "@openzeppelin/contracts/interfaces/draft-IERC6909.sol";
Optional extension of IERC6909
that adds a token supply function.
Functions
Events
totalSupply(uint256 id) → uint256
external
#Returns the total supply of the token of type id
.
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
Minimal configuration interface for ERC-7579 modules
onInstall(bytes data)
external
#This function is called by the smart account during installation of the module
onUninstall(bytes data)
external
#This function is called by the smart account during uninstallation of the module
isModuleType(uint256 moduleTypeId) → bool
external
#Returns boolean value if module is a certain type
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
ERC-7579 Validation module (type 1).
A module that implements logic to validate user operations and signatures.
Functions
validateUserOp(struct PackedUserOperation userOp, bytes32 userOpHash) → uint256
external
#Validates a UserOperation
isValidSignatureWithSender(address sender, bytes32 hash, bytes signature) → bytes4
external
#Validates a signature using ERC-1271
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
ERC-7579 Hooks module (type 4).
A module that implements logic to execute before and after the account executes a user operation, either individually or batched.
Functions
preCheck(address msgSender, uint256 value, bytes msgData) → bytes hookData
external
#Called by the smart account before execution
postCheck(bytes hookData)
external
#Called by the smart account after execution
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
ERC-7579 Execution.
Accounts should implement this interface so that the Entrypoint and ERC-7579 modules can execute operations.
execute(bytes32 mode, bytes executionCalldata)
external
#Executes a transaction on behalf of the account.
executeFromExecutor(bytes32 mode, bytes executionCalldata) → bytes[] returnData
external
#Executes a transaction on behalf of the account. This function is intended to be called by Executor Modules
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
ERC-7579 Account Config.
Accounts should implement this interface to expose information that identifies the account, supported modules and capabilities.
accountId() → string accountImplementationId
external
#Returns the account id of the smart account
supportsExecutionMode(bytes32 encodedMode) → bool
external
#Function to check if the account supports a certain execution mode (see above)
supportsModule(uint256 moduleTypeId) → bool
external
#Function to check if the account supports a certain module typeId
import "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
ERC-7579 Module Config.
Accounts should implement this interface to allow installing and uninstalling modules.
Functions
installModule(uint256 moduleTypeId, address module, bytes initData)
external
#Installs a Module of a certain type on the smart account
uninstallModule(uint256 moduleTypeId, address module, bytes deInitData)
external
#Uninstalls a Module of a certain type on the smart account
isModuleInstalled(uint256 moduleTypeId, address module, bytes additionalContext) → bool
external
#Returns whether a module is installed on the smart account
ModuleInstalled(uint256 moduleTypeId, address module)
event
#ModuleUninstalled(uint256 moduleTypeId, address module)
event
#import "@openzeppelin/contracts/interfaces/draft-IERC7674.sol";
Temporary Approval Extension for ERC-20 (ERC-7674)
Functions
temporaryApprove(address spender, uint256 value) → bool success
external
#Set the temporary allowance, allowing spender
to withdraw (within the same transaction) assets
held by the caller.
import "@openzeppelin/contracts/interfaces/draft-IERC7786.sol";
Interface for ERC-7786 source gateways.
See ERC-7786 for more details
supportsAttribute(bytes4 selector) → bool
external
#Getter to check whether an attribute is supported or not.
sendMessage(bytes recipient, bytes payload, bytes[] attributes) → bytes32 sendId
external
#Endpoint for creating a new message. If the message requires further (gateway specific) processing before
it can be sent to the destination chain, then a non-zero outboxId
must be returned. Otherwise, the
message MUST be sent and this function must return 0.
- MUST emit a
IERC7786GatewaySource.MessageSent
event.
If any of the attributes
is not supported, this function SHOULD revert with an IERC7786GatewaySource.UnsupportedAttribute
error.
Other errors SHOULD revert with errors not specified in ERC-7786.
MessageSent(bytes32 indexed sendId, bytes sender, bytes receiver, bytes payload, uint256 value, bytes[] attributes)
event
#Event emitted when a message is created. If outboxId
is zero, no further processing is necessary. If
outboxId
is not zero, then further (gateway specific, and non-standardized) action is required.
UnsupportedAttribute(bytes4 selector)
error
#This error is thrown when a message creation fails because of an unsupported attribute being specified.
import "@openzeppelin/contracts/interfaces/draft-IERC7786.sol";
Interface for the ERC-7786 client contract (receiver).
See ERC-7786 for more details
executeMessage(bytes32 receiveId, bytes sender, bytes payload, bytes[] attributes) → bytes4
external
#Endpoint for receiving cross-chain message.
This function may be called directly by the gateway.
import "@openzeppelin/contracts/interfaces/draft-IERC7802.sol";
Functions
crosschainMint(address _to, uint256 _amount)
external
#crosschainBurn(address _from, uint256 _amount)
external
#CrosschainMint(address indexed to, uint256 amount, address indexed sender)
event
#CrosschainBurn(address indexed from, uint256 amount, address indexed sender)
event
#import "@openzeppelin/contracts/interfaces/draft-IERC7821.sol";
Interface for minimal batch executor.
execute(bytes32 mode, bytes executionData)
external
#Executes the calls in executionData
.
Reverts and bubbles up error if any call fails.
executionData
encoding:
- If
opData
is empty,executionData
is simplyabi.encode(calls)
. - Else,
executionData
isabi.encode(calls, opData)
. See: https://eips.ethereum.org/EIPS/eip-7579
Supported modes:
bytes32(0x01000000000000000000...)
: does not support optionalopData
.bytes32(0x01000000000078210001...)
: supports optionalopData
.
Authorization checks:
- If
opData
is empty, the implementation SHOULD require thatmsg.sender == address(this)
. - If
opData
is not empty, the implementation SHOULD use the signature encoded inopData
to determine if the caller can perform the execution.
opData
may be used to store additional data for authentication,
paymaster data, gas limits, etc.
For calldata compression efficiency, if a Call.to is address(0)
,
it will be replaced with address(this)
.
supportsExecutionMode(bytes32 mode) → bool
external
#This function is provided for frontends to detect support. Only returns true for:
bytes32(0x01000000000000000000...)
: does not support optionalopData
.bytes32(0x01000000000078210001...)
: supports optionalopData
.