Skip to main content

Managed Account Factory

import "@thirdweb-dev/contracts/smart-wallet/managed/ManagedAccountFactory.sol";

This contract inherits from the BaseAccountFactory contract.

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


info

If you modify the ManagedAccount 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 ManagedAccountFactory smart contract:

npx thirdweb create contract

Deploy your contract using the deploy cli command:

npx thirdweb create

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

import "@thirdweb-dev/contracts/smart-wallet/managed/ManagedAccountFactory.sol";

contract MyManagedAccountFactory is ManagedAccountFactory {
constructor(
IEntryPoint _entrypoint
)
ManagedAccountFactory(
_entrypoint
)
{}
}

Functions to Override

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 {
ManagedAccount(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 {
ManagedAccount.initialize(_admin, _data);
}
_canSetExtension

Returns whether an extension can be set in the given execution context.

function _canSetExtension() internal view virtual override returns (bool) {
return hasRole(DEFAULT_ADMIN_ROLE, msg.sender);
}