Skip to content

Solidity API

ERC20Permit

derived from https://github.com/soliditylabs/ERC20-Permit (MIT license)

DOMAIN_SEPARATOR

solidity
function DOMAIN_SEPARATOR() external view returns (bytes32 domainSeparator)

Returns the EIP-712 domain separator unique to the contract and chain

The domain separator is used as part of the permit signature verification process. It includes contract-specific information (name, version) and chain-specific data (chainId, contract address) to prevent signature replay attacks across different contracts or chains.

Return Values

NameTypeDescription
domainSeparatorbytes32The 32-byte domain separator value

nonces

solidity
function nonces(address owner) public view returns (uint256)

Returns the current nonce for a given address

The nonce is incremented each time a permit is used, preventing signature replay attacks. Each owner's nonce starts at 0 and increases monotonically with each permit operation.

Parameters

NameTypeDescription
owneraddressThe address whose nonce is being queried

Return Values

NameTypeDescription
[0]uint256The current nonce value for the specified address

permit

solidity
function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual

Approves spender to transfer tokens held by owner via signature

_Implements the EIP-2612 permit function. The signature is created using EIP-712 structured data signing. The deadline parameter helps prevent old signatures from being replayed.

The function validates:

  1. The deadline hasn't passed
  2. The signature is valid and from the token owner
  3. The nonce matches the owner's current nonce

After validation, it:

  1. Increments the owner's nonce
  2. Sets the approval amount for the spender_

Parameters

NameTypeDescription
owneraddressThe address that owns the tokens and signed the permit
spenderaddressThe address that will be approved to spend the tokens
amountuint256The number of tokens that can be spent
deadlineuint256The timestamp after which the permit is no longer valid
vuint8The recovery byte of the signature (ECDSA parameter)
rbytes32The first 32 bytes of the signature (ECDSA parameter)
sbytes32The second 32 bytes of the signature (ECDSA parameter)