pay Function
Function Type: external
Function Signature: pay(address,address,string,address,uint256,uint256,uint256,bool,address,bytes)
The pay
function is the primary payment processor in the EVVM ecosystem, enabling single payments with intelligent staker detection and reward distribution. This function automatically detects whether the executor (msg.sender
) is a staker and applies the appropriate logic: stakers receive priority fees and principal token rewards, while non-stakers can still process transactions but without additional benefits.
The function supports both synchronous and asynchronous nonce management through the priorityFlag
parameter, making it flexible for various execution patterns and use cases. For details on nonce types, see Nonce Types in EVVM. For signature details, see Payment Signature Structure.
Processes single payments with automatic staker detection and reward distribution. It supports both synchronous and asynchronous nonce management through the priorityFlag
parameter, making it flexible for various execution patterns. If the executor (msg.sender
) is a staker, they receive priority fees and principal token rewards.
Parameters
Field | Type | Description |
---|---|---|
from | address | The address of the payment sender whose funds are being transferred and whose signature/nonce are validated. |
to_address | address | Direct recipient address. Used when to_identity is empty. |
to_identity | string | Username/identity of the recipient. If provided, the contract resolves it to an address via the NameService. |
token | address | The token contract address for the transfer. |
amount | uint256 | The quantity of tokens to transfer from from to the recipient. |
priorityFee | uint256 | Additional fee for transaction priority. If the executor is a staker, they receive this fee as a reward. |
nonce | uint256 | Transaction nonce value. Usage depends on priorityFlag : if false (sync), this value is ignored and automatic nonce is used. |
priorityFlag | bool | Execution type flag: false = synchronous nonce (sequential), true = asynchronous nonce (custom). |
executor | address | Address authorized to execute this transaction. Use address(0) to allow any address to execute. |
signature | bytes | Cryptographic signature (EIP-191) from the from address authorizing this payment. |
The nonce
parameter usage depends on priorityFlag
: when false
(synchronous), the nonce is automatically managed and the provided value is ignored; when true
(asynchronous), the provided nonce value is used for custom ordering.
Execution Methods
The function can be executed in multiple ways:
Fisher Execution
- A user signs the payment details and sends the request (parameters + signature) to a fishing spot.
- A fisher (preferably a staker for rewards) captures the transaction and validates the request.
- The fisher submits the transaction to the function for processing and receives rewards if they are a staker.
Direct Execution
- The user or any authorized service directly calls the
pay
function. - If an
executor
address is specified, only that address can submit the transaction. - If
executor
is set toaddress(0)
, anyone can execute the transaction with a valid signature.
When using a service as the executor, we recommend specifying the service's address in the executor
parameter for additional security.
Workflow
- Signature Verification: Validates the
signature
against thefrom
address and other parameters usingverifyMessageSignedForPay
. For synchronous payments (priorityFlag = false
), usesnextSyncUsedNonce[from]
as the nonce; for asynchronous payments (priorityFlag = true
), uses the providednonce
parameter. Reverts withInvalidSignature
on failure. - Executor Validation: If
executor
is notaddress(0)
, checks thatmsg.sender
matches theexecutor
address. Reverts withSenderIsNotTheExecutor
if they don't match. - Asynchronous Nonce Verification: For asynchronous payments only (
priorityFlag = true
), checks if the providednonce
has already been used for thefrom
address by consulting theasyncUsedNonce
mapping. Reverts withInvalidAsyncNonce
if the nonce has already been used. - Resolve Recipient Address: Determines the final recipient address:
- If
to_identity
is provided (not empty), resolves the identity to an owner address usingverifyStrictAndGetOwnerOfIdentity
from the NameService contract. - If
to_identity
is empty, uses the providedto_address
.
- If
- Balance Update: Executes the payment transfer using the
_updateBalance
function, sendingamount
oftoken
from thefrom
address to the resolved recipient address. Reverts withUpdateBalanceFailed
on transfer failure. - Staker Benefits Distribution: If the executor (
msg.sender
) is a registered staker:- Priority Fee Transfer: If
priorityFee > 0
, transfers thepriorityFee
amount oftoken
from thefrom
address to themsg.sender
(executor) as a staker reward. - Principal Token Reward: Grants 1x reward amount in principal tokens to the
msg.sender
(executor) using the_giveReward
function.
- Priority Fee Transfer: If
- Nonce Management: Updates nonce tracking based on execution type:
- Asynchronous (
priorityFlag = true
): Marks the specificnonce
as used (true
) for thefrom
address in theasyncUsedNonce
mapping. - Synchronous (
priorityFlag = false
): Increments the synchronous nonce counter for thefrom
address to prevent replay attacks.
- Asynchronous (
For more information about the signature structure, refer to the Payment Signature Structure section.