MetaMask Smart Accounts
The MetaMask Smart Accounts Kit enables embedding MetaMask Smart Accounts into dapps. Smart accounts support programmable account behavior and advanced features like delegated permissions, multi-signature approvals, and gas abstraction. Delegation is a core feature of smart accounts, enabling secure, rule-based permission sharing.
Use MetaMask smart accounts with Arbitrum
The MetaMask Smart Accounts Kit supports multiple networks, including Arbitrum One, Arbitrum Nova, and Arbitrum Sepolia.
Follow these steps to create your first smart account and send a user operation.
1. Install the Smart Accounts Kit
Install the Smart Accounts Kit in your project:
- npm
- Yarn
npm install @metamask/smart-accounts-kit
yarn add @metamask/smart-accounts-kit
2. Set up a public client
Set up a Viem Public Client using Viem's createPublicClient function.
This client will let the smart account query the signer's account state and interact with the blockchain network.
Make sure to import your desired Arbitrum network from viem/chains.
- Arbitrum One
- Arbitrum Nova
- Arbitrum Sepolia
import { createPublicClient, http } from 'viem';
import { arbitrum as chain } from 'viem/chains';
const publicClient = createPublicClient({
chain,
transport: http(),
});
import { createPublicClient, http } from 'viem';
import { arbitrumNova as chain } from 'viem/chains';
const publicClient = createPublicClient({
chain,
transport: http(),
});
import { createPublicClient, http } from 'viem';
import { arbitrumSepolia as chain } from 'viem/chains';
const publicClient = createPublicClient({
chain,
transport: http(),
});
3. Set up a bundler client
Set up a Viem Bundler Client using Viem's createBundlerClient function.
This lets you use the bundler service to estimate gas for user operations and submit transactions to the network.
import { createBundlerClient } from 'viem/account-abstraction';
const bundlerClient = createBundlerClient({
client: publicClient,
transport: http('https://your-bundler-rpc.com'),
});
4. Create a MetaMask smart account
Create a MetaMask smart account to send the first user operation. This example configures a Hybrid smart account, which is a flexible smart account implementation that supports both an externally owned account (EOA) owner and any number of passkey (WebAuthn) signers:
import { Implementation, toMetaMaskSmartAccount } from '@metamask/smart-accounts-kit';
import { privateKeyToAccount } from 'viem/accounts';
const account = privateKeyToAccount('0x...');
const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [account.address, [], [], []],
deploySalt: '0x',
signer: { account },
});
Learn more about creating MetaMask Smart Accounts.
5. Send a user operation
Send a user operation using Viem's sendUserOperation method.
The smart account will remain counterfactual until the first user operation.
If the smart account is not deployed, it will be automatically deployed upon the sending first user operation.
import { parseEther } from 'viem';
// Appropriate fee per gas must be determined for the specific bundler being used.
const maxFeePerGas = 1n;
const maxPriorityFeePerGas = 1n;
const userOperationHash = await bundlerClient.sendUserOperation({
account: smartAccount,
calls: [
{
to: '0x1234567890123456789012345678901234567890',
value: parseEther('1'),
},
],
maxFeePerGas,
maxPriorityFeePerGas,
});
Learn more about sending user operations.
Next steps
Now that you have created and deployed a MetaMask smart account on Arbitrum, you can grant specific permissions to other accounts from your smart account. See MetaMask's documentation on how to create a delegation.