Skip to main content

Account Factory

import "@thirdweb-dev/contracts/smart-wallet/non-upgradeable/AccountFactory.sol";

This contract inherits from the BaseAccountFactory contract.

This factory smart contract is intended to be used to distribute 'Accounts` programmatically.


info

If you modify the Account contract, it is recommended that you write your own factory contract by inheriting from the BaseAccountFactory extension.

Detected Extensions

Once deployed, you can use the features made available by these extensions on the SDK and dashboard:

Click on each feature to learn more about what functions are available.

Usage

Use the CLI create command to create a AccountFactory smart contract:

npx thirdweb create contract

Deploy your contract using the deploy cli command:

npx thirdweb deploy

Or import the contract into your existing project and inherit from it.

import "@thirdweb-dev/contracts/smart-wallet/non-upgradable/AccountFactory.sol";

contract MyAccountFactory is AccountFactory {
constructor(
IEntryPoint _entrypoint
)
AccountFactory(
_entrypoint
)
{}
}

Full Reference

The following functions have been implemented on this contract & are available to be overridden to add custom logic:

_initializeAccount

Called in createAccount. Initializes the account contract created in createAccount.

function _initializeAccount(
address _account,
address _admin,
bytes calldata _data
) internal override {
Account(payable(_account)).initialize(_admin, _data);
}

_account

The address of the smart account smart contract to initialize.

_admin

The address to be set as default admin role for the contract. Must be of type address.

_data

If extra storage variables are required in your account contract, abi encode the variables, pass them to this function as the bytes argument.

For example:


function initializeAccount(
address _admin,
bytes calldata _data
) public override initializer {
Account.initialize(_admin, _data);
}