BaseAccount - bcnmy/nexus GitHub Wiki

Table of Contents


BaseAccount

Inherits: IBaseAccount

Implements ERC-4337 and ERC-7579 standards for account management and access control within the Nexus suite.

Manages entry points and configurations as specified in the ERC-4337 and ERC-7579 documentation.


State Variables

_ACCOUNT_IMPLEMENTATION_ID

Identifier for this implementation on the network.

string internal constant _ACCOUNT_IMPLEMENTATION_ID = "biconomy.nexus.1.0.0-beta";

Note

_ACCOUNT_IMPLEMENTATION_ID: This constant helps in identifying the specific implementation of the account within the network, ensuring consistency and version control.


_ENTRYPOINT

The canonical address for the ERC4337 EntryPoint contract, version 0.7. This address is consistent across all supported networks.

address internal immutable _ENTRYPOINT;

Important

_ENTRYPOINT: Ensures that all transactions and operations are funneled through a consistent and secure entry point, enhancing security and interoperability across different networks.


Functions

onlyEntryPointOrSelf

Ensures the caller is either the EntryPoint or this account itself. Reverts with AccountAccessUnauthorized if the check fails.

modifier onlyEntryPointOrSelf();

Caution

Security Check: This modifier restricts function access to the EntryPoint or the account itself, preventing unauthorized access and enhancing security.


onlyEntryPoint

Ensures the caller is the EntryPoint. Reverts with AccountAccessUnauthorized if the check fails.

modifier onlyEntryPoint();

Warning

Strict Access Control: Only the EntryPoint can call functions protected by this modifier, ensuring tight control over critical operations.


payPrefund

Sends to the EntryPoint (i.e., msg.sender) the missing funds for this transaction. Subclass MAY override this modifier for better funds management. (e.g., send to the EntryPoint more than the minimum required, so that in future transactions it will not be required to send again) missingAccountFunds is the minimum value this modifier should send the EntryPoint, which MAY be zero, in case there is enough deposit, or the userOp has a paymaster.

modifier payPrefund(uint256 missingAccountFunds) virtual;

Tip

Funds Management: This modifier helps manage the account's funds efficiently, ensuring that the EntryPoint always has the necessary funds for transactions.


addDeposit

Adds deposit to the EntryPoint to fund transactions.

function addDeposit() external payable virtual;

Note

addDeposit: This function allows users to add funds to their EntryPoint deposit, ensuring sufficient balance for future transactions.


withdrawDepositTo

Withdraws ETH from the EntryPoint to a specified address.

function withdrawDepositTo(address to, uint256 amount) external payable virtual onlyEntryPointOrSelf;

Parameters

Name Type Description
to address The address to receive the withdrawn funds.
amount uint256 The amount to withdraw.

Important

withdrawDepositTo: Ensures controlled and authorized withdrawal of funds, maintaining account integrity and preventing unauthorized access.


nonce

Gets the nonce for a particular key.

function nonce(uint192 key) external view virtual returns (uint256);

Parameters

Name Type Description
key uint192 The nonce key.

Returns

Name Type Description
<none> uint256 The nonce associated with the key.

Note

nonce: This function helps in tracking the transaction sequence, preventing replay attacks and ensuring transaction integrity.


getDeposit

Returns the current deposit balance of this account on the EntryPoint.

function getDeposit() external view virtual returns (uint256 result);

Returns

Name Type Description
result uint256 The current balance held at the EntryPoint.

Tip

getDeposit: Allows users to check their deposit balance, aiding in funds management and planning for future transactions.


entryPoint

Retrieves the address of the EntryPoint contract, currently using version 0.7.

This function returns the address of the canonical ERC4337 EntryPoint contract. It can be overridden to return a different EntryPoint address if needed.

function entryPoint() external view returns (address);

Returns

Name Type Description
<none> address The address of the EntryPoint contract.

Note

entryPoint: This function ensures that all interactions are directed through the correct EntryPoint, maintaining consistency and security.


⚠️ **GitHub.com Fallback** ⚠️