diff --git a/delegation-toolkit/get-started/delegation-quickstart.md b/delegation-toolkit/get-started/delegation-quickstart.md deleted file mode 100644 index 04db513d813..00000000000 --- a/delegation-toolkit/get-started/delegation-quickstart.md +++ /dev/null @@ -1,174 +0,0 @@ ---- -description: Get started quickly with the MetaMask Delegation Toolkit. -sidebar_position: 3 -sidebar_label: Delegation quickstart ---- - -# Delegation quickstart - -[Delegation](../concepts/delegation.md) is the ability for a [MetaMask smart account](../concepts/smart-accounts.md) to grant permission to another account to perform executions on its behalf. - -In this quickstart, you will create a *delegator account* (the account that grants the permission) and *delegate account* (the account that receives the permission), and complete the delegation lifecycle (create, sign, and redeem a delegation). - -This quickstart will refer to the delegator account as "Alice," who grants permission to "Bob," the delegate account, to perform executions on her behalf. - -## Prerequisites - -[Install and set up the Delegation Toolkit.](install.md) - -## Steps - -### 1. Set up a Public Client - -Set up a [Viem Public Client](https://viem.sh/docs/clients/public) using Viem's `createPublicClient` function. This client will let the delegator account query the signer's account state and interact with smart contracts. - -```typescript -import { createPublicClient, http } from 'viem' -import { sepolia as chain } from 'viem/chains' - -const publicClient = createPublicClient({ - chain, - transport: http(), -}) -``` - -### 2. Set up a Bundler Client - -Set up a [Viem Bundler Client](https://viem.sh/account-abstraction/clients/bundler) using Viem's `createBundlerClient` function. This lets you use the bundler service to estimate gas for user operations and submit transactions to the network. - -```typescript -import { createBundlerClient } from 'viem/account-abstraction' - -const bundlerClient = createBundlerClient({ - client: publicClient, - transport: http('https://your-bundler-rpc.com'), -}) -``` - -### 3. Create a delegator account - -Create an account to represent Alice, the delegator who will create a delegation. -The delegator must be a [MetaMask smart account](../concepts/smart-accounts.md). - -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 P256 (passkey) signers: - -```typescript -import { Implementation, toMetaMaskSmartAccount } from '@metamask/delegation-toolkit' -import { privateKeyToAccount } from 'viem/accounts' - -const delegatorAccount = privateKeyToAccount('0x...') - -const delegatorSmartAccount = await toMetaMaskSmartAccount({ - client: publicClient, - implementation: Implementation.Hybrid, - deployParams: [delegatorAccount.address, [], [], []], - deploySalt: '0x', - signatory: { account: delegatorAccount }, -}) -``` - -:::note -See [how to configure other smart account types](../how-to/create-smart-account.md). -::: - -### 4. Create a delegate account - -Create an account to represent Bob, the delegate who will receive the delegation. The delegate can be a smart account or an externally owned account (EOA). - -This example configures a Hybrid smart account: - -```typescript -import { Implementation, toMetaMaskSmartAccount } from '@metamask/delegation-toolkit' -import { privateKeyToAccount } from 'viem/accounts' - -const delegateAccount = privateKeyToAccount('0x...') - -const delegateSmartAccount = await toMetaMaskSmartAccount({ - client: publicClient, - implementation: Implementation.Hybrid, - deployParams: [delegateAccount.address, [], [], []], - deploySalt: '0x', - signatory: { account: delegateAccount }, -}) -``` - -### 5. Create a delegation - -[Create a root delegation](../how-to/create-delegation/index.md#create-a-root-delegation) from Alice to Bob. -A root delegation is a delegation that doesn't derive its authority from another delegation. -Alice is delegating her own authority away, as opposed to *redelegating* permissions she received from a previous delegation. - -This example passes an empty `caveats` array, which means Bob can perform any action on Alice's behalf. We recommend [restricting the delegation](../how-to/create-delegation/restrict-delegation.md) by adding caveat enforcers. -For example, Alice can delegate the ability to spend her USDC to Bob, limiting the amount to 100 USDC. - -:::warning Important - -Before creating a delegation, ensure that the delegator account (in this example, Alice's account) has been deployed. If the account is not deployed, redeeming the delegation will fail. - -::: - -```typescript -import { createDelegation } from '@metamask/delegation-toolkit' - -const delegation = createDelegation({ - to: delegateSmartAccount.address, - from: delegatorSmartAccount.address, - caveats: [], // Empty caveats array - we recommend adding appropriate restrictions. -}) -``` - -### 6. Sign the delegation - -[Sign the delegation](../how-to/create-delegation/index.md#sign-a-delegation) with Alice's account, using the [`signDelegation`](../reference/api/smart-account.md#signdelegation) method from `MetaMaskSmartAccount`. Alternatively, you can use the Delegation Toolkit's [`signDelegation`](../reference/api/delegation.md#signdelegation) utility. Bob will later use the signed delegation to perform actions on Alice's behalf. - -```typescript -const signature = await delegatorSmartAccount.signDelegation({ - delegation, -}) - -const signedDelegation = { - ...delegation, - signature, -} -``` - -### 7. Redeem the delegation - -Bob can now [redeem the delegation](../how-to/redeem-delegation.md). The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on Alice's behalf. - -To prepare the calldata for the redeem transaction, use the [`redeemDelegation`](../reference/api/delegation.md#redeemdelegation) utility function from the Delegation Toolkit. - -```typescript -import { createExecution } from '@metamask/delegation-toolkit' -import { DelegationManager } from '@metamask/delegation-toolkit/contracts' -import { SINGLE_DEFAULT_MODE } from '@metamask/delegation-toolkit/utils' -import { zeroAddress } from 'viem' - -const delegations = [signedDelegation] - -const executions = createExecution({ target: zeroAddress }) - -const redeemDelegationCalldata = DelegationManager.encode.redeemDelegations({ - delegations: [delegations], - modes: [SINGLE_DEFAULT_MODE], - executions: [executions], -}) - -const userOperationHash = await bundlerClient.sendUserOperation({ - account: delegateSmartAccount, - calls: [ - { - to: delegateSmartAccount.address, - data: redeemDelegationCalldata, - }, - ], - maxFeePerGas: 1n, - maxPriorityFeePerGas: 1n, -}) -``` - -:::note -If Bob's account (the delegate account) is an externally owned account (EOA) instead of a smart account, -see [how to redeem the delegation with an EOA](../how-to/redeem-delegation.md#redeem-with-an-eoa). -::: diff --git a/delegation-toolkit/get-started/erc7715-quickstart.md b/delegation-toolkit/get-started/erc7715-quickstart.md index 9b5d5b11aeb..09b89d8fbf9 100644 --- a/delegation-toolkit/get-started/erc7715-quickstart.md +++ b/delegation-toolkit/get-started/erc7715-quickstart.md @@ -1,18 +1,18 @@ --- description: Learn how to use ERC-7715 to request permissions. -sidebar_position: 5 +sidebar_position: 3 sidebar_label: ERC-7715 quickstart --- # ERC-7715 quickstart -This page demonstrates how to use [ERC-7715](https://eips.ethereum.org/EIPS/eip-7715) to request permissions -from a wallet, and execute transactions on a user's behalf. +The Delegation Toolkit supports [ERC-7715](https://eips.ethereum.org/EIPS/eip-7715), which enables you to request permissions from MetaMask and execute transactions on a user's behalf. +This quickstart demonstrates how to request and redeem ERC-7715 permissions. ## Prerequisites - [Install and set up the Delegation Toolkit.](install.md) -- [Install MetaMask Flask 12.14.2 or later](/snaps/get-started/install-flask). +- [Install MetaMask Flask 12.14.2 or later.](/snaps/get-started/install-flask) ## Steps @@ -160,3 +160,7 @@ const userOperationHash = await bundlerClient.sendUserOperationWithDelegation({ accountMetadata, }); ``` + +## Next steps + +To quickly bootstrap an ERC-7715 project, you can [use the CLI](use-the-cli.md). diff --git a/delegation-toolkit/get-started/install.md b/delegation-toolkit/get-started/install.md index cdfbe899e99..0e33574b33c 100644 --- a/delegation-toolkit/get-started/install.md +++ b/delegation-toolkit/get-started/install.md @@ -44,5 +44,5 @@ Add `@metamask/delegation-framework/=lib/metamask/delegation-framework/` in your ### 3. Get started -You're now ready to start using MetaMask Smart Accounts. -Check out the [quickstart](quickstart.md) to walk through a simple example. +You're now ready to start using the Delegation Toolkit. +Check out the [MetaMask Smart Accounts quickstart](smart-account-quickstart/index.md) to walk through a simple example. diff --git a/delegation-toolkit/get-started/llm-context.md b/delegation-toolkit/get-started/llm-context.md deleted file mode 100644 index 63ead6da5a5..00000000000 --- a/delegation-toolkit/get-started/llm-context.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -sidebar_label: LLM context -description: Context about the MetaMask Delegation Toolkit that can be provided to an LLM. -sidebar_position: 4 -sidebar_class_name: hidden ---- - -# Delegation Toolkit LLM context - -This website contains an [`LLMs.txt`](/llms.txt) file that is intended for use by large language models (LLMs). -It provides information about the structure of the MetaMask developer documentation, -to facilitate better indexing, summarization, and understanding by LLMs. - -You can add this file to an LLM-based tool like [ChatGPT](https://chatgpt.com/) or [Cursor](https://docs.cursor.com/context/@-symbols/@-docs), -to provide detailed context about the MetaMask developer documentation. diff --git a/delegation-toolkit/get-started/eip7702-quickstart.md b/delegation-toolkit/get-started/smart-account-quickstart/eip7702.md similarity index 88% rename from delegation-toolkit/get-started/eip7702-quickstart.md rename to delegation-toolkit/get-started/smart-account-quickstart/eip7702.md index fbb80f26cd7..3e432864dfb 100644 --- a/delegation-toolkit/get-started/eip7702-quickstart.md +++ b/delegation-toolkit/get-started/smart-account-quickstart/eip7702.md @@ -1,19 +1,19 @@ --- description: Upgrade an externally owned account (EOA) to a smart account -sidebar_position: 4 +sidebar_position: 1 sidebar_label: EIP-7702 quickstart --- # EIP-7702 quickstart -This page demonstrates how to upgrade your externally owned account (EOA) to support MetaMask Smart Accounts +This quickstart demonstrates how to upgrade your externally owned account (EOA) to support MetaMask Smart Accounts functionality using an [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) transaction. This enables your EOA to leverage the benefits of account -abstraction, such as batch transactions, gas sponsorship, and [ERC-7710 delegation capabilities](./../concepts/delegation.md). +abstraction, such as batch transactions, gas sponsorship, and [ERC-7710 delegation capabilities](../../concepts/delegation.md). ## Prerequisites -- [Install and set up the Delegation Toolkit.](install.md) -- [Install Viem](https://viem.sh/) +- [Install and set up the Delegation Toolkit.](../install.md) +- [Install Viem.](https://viem.sh/) ## Steps @@ -153,3 +153,8 @@ const userOperationHash = await bundlerClient.sendUserOperation({ maxPriorityFeePerGas }); ``` + +## Next steps + +- With a MetaMask smart account, you can [create delegations](../../how-to/create-delegation/index.md) that can be used to grant specific rights and permissions to other accounts. +- To quickly bootstrap a MetaMask Smart Accounts project, you can [use the CLI](../use-the-cli.md). diff --git a/delegation-toolkit/get-started/quickstart.md b/delegation-toolkit/get-started/smart-account-quickstart/index.md similarity index 71% rename from delegation-toolkit/get-started/quickstart.md rename to delegation-toolkit/get-started/smart-account-quickstart/index.md index 6a43fb205d4..fedb30032d5 100644 --- a/delegation-toolkit/get-started/quickstart.md +++ b/delegation-toolkit/get-started/smart-account-quickstart/index.md @@ -6,11 +6,11 @@ sidebar_label: Smart account quickstart # MetaMask Smart Accounts quickstart -This page demonstrates how to get started quickly with [MetaMask Smart Accounts](../concepts/smart-accounts.md), and send the first user operation. +You can get started quickly with [MetaMask Smart Accounts](../../concepts/smart-accounts.md) by creating your first smart account and sending a user operation. ## Prerequisites -[Install and set up the Delegation Toolkit.](install.md) +[Install and set up the Delegation Toolkit.](../install.md) ## Steps @@ -43,7 +43,7 @@ const bundlerClient = createBundlerClient({ ### 3. Create a MetaMask smart account -[Create a MetaMask smart account](../how-to/create-smart-account.md) to send the first user operation. +[Create a MetaMask smart account](../../how-to/create-smart-account.md) 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 P256 (passkey) signers: @@ -63,15 +63,11 @@ const smartAccount = await toMetaMaskSmartAccount({ }); ``` -:::note -See [how to configure other smart account types](../how-to/create-smart-account.md). -::: - ### 4. Send a user operation Send a user operation using Viem's [`sendUserOperation`](https://viem.sh/account-abstraction/actions/bundler/sendUserOperation) method. -See [send user operation](./../how-to/send-user-operation.md) to learn how to estimate fee per gas, and wait for the transaction receipt. +See [Send a user operation](../../how-to/send-user-operation.md) to learn how to estimate fee per gas, and wait for the transaction receipt. 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. @@ -94,4 +90,12 @@ const userOperationHash = await bundlerClient.sendUserOperation({ maxFeePerGas, maxPriorityFeePerGas, }); -``` \ No newline at end of file +``` + +## Next steps + +- With a MetaMask smart account, you can [create delegations](../../how-to/create-delegation/index.md) that can be used to grant specific rights and permissions to other accounts. +- This quickstart example uses a Hybrid smart account. + You can also [configure other smart account types](../../how-to/create-smart-account/configure-accounts-signers.md). +- To upgrade an EOA to a smart account, see the [EIP-7702 quickstart](eip7702-quickstart.md). +- To quickly bootstrap a MetaMask Smart Accounts project, you can [use the CLI](../use-the-cli.md). diff --git a/delegation-toolkit/get-started/supported-networks.md b/delegation-toolkit/get-started/supported-networks.md index 0e761ddf1bb..480bbf7b924 100644 --- a/delegation-toolkit/get-started/supported-networks.md +++ b/delegation-toolkit/get-started/supported-networks.md @@ -2,7 +2,7 @@ title: Supported networks sidebar_label: Supported networks description: Supported networks for Delegation Toolkit. -sidebar_position: 7 +sidebar_position: 5 --- The following tables display the networks supported by each version of the MetaMask Delegation Toolkit. diff --git a/delegation-toolkit/get-started/cli-quickstart.md b/delegation-toolkit/get-started/use-the-cli.md similarity index 97% rename from delegation-toolkit/get-started/cli-quickstart.md rename to delegation-toolkit/get-started/use-the-cli.md index 6d576a95325..0685cb66a0d 100644 --- a/delegation-toolkit/get-started/cli-quickstart.md +++ b/delegation-toolkit/get-started/use-the-cli.md @@ -1,10 +1,10 @@ --- description: Get started with the MetaMask Delegation Toolkit using the `@metamask/create-gator-app` CLI. -sidebar_position: 6 -sidebar_label: CLI quickstart +sidebar_position: 4 +sidebar_label: Use the CLI --- -# Delegation Toolkit CLI quickstart +# Use the Delegation Toolkit CLI Use the `@metamask/create-gator-app` interactive CLI to bootstrap a project with the MetaMask Delegation Toolkit in under two minutes. The CLI automatically installs the required dependencies and sets up a project structure using a selected template, @@ -94,4 +94,4 @@ Currently, only Cursor and Windsurf are supported. |----------------------------------------------------|---------|------------| | MetaMask Smart Accounts Starter | ✅ | ✅ | | MetaMask Smart Accounts & Delegation Starter | ✅ | ✅ | -| Experimental: ERC7715 Permissions starter | ✅ | | +| Experimental: ERC7715 Permissions starter | ✅ | | diff --git a/delegation-toolkit/index.md b/delegation-toolkit/index.md index febbd212381..943740f8b11 100644 --- a/delegation-toolkit/index.md +++ b/delegation-toolkit/index.md @@ -46,17 +46,12 @@ Check out the following guides to get started with the MetaMask Delegation Toolk description: "Install and set up the MetaMask Delegation Toolkit.", }, { - href: "get-started/quickstart", + href: "get-started/smart-account-quickstart", title: "MetaMask Smart Accounts quickstart", description: "Create a MetaMask smart account and send a user operation.", }, { - href: "get-started/delegation-quickstart", - title: "Delegation quickstart", - description: "Create, sign, and redeem a delegation.", - }, - { - href: "get-started/eip7702-quickstart", + href: "get-started/smart-account-quickstart/eip7702", title: "EIP-7702 quickstart", description: "Upgrade an externally owned account to a smart account.", }, @@ -66,8 +61,8 @@ Check out the following guides to get started with the MetaMask Delegation Toolk description: "Request permissions from MetaMask and execute transactions on a user's behalf.", }, { - href: "get-started/cli-quickstart", - title: "CLI quickstart", + href: "get-started/use-the-cli", + title: "Use the CLI", description: "Use the Delegation Toolkit CLI to bootstrap a project.", } ]} diff --git a/vercel.json b/vercel.json index 21e11e4bffa..d2c9cfb937f 100644 --- a/vercel.json +++ b/vercel.json @@ -714,6 +714,18 @@ "source": "/delegation-toolkit/development/how-to/create-smart-account/configure-accounts-signers/", "destination": "/delegation-toolkit/development/how-to/create-smart-account/" }, + { + "source": "/delegation-toolkit/development/get-started/quickstart/", + "destination": "/delegation-toolkit/development/get-started/smart-account-quickstart/" + }, + { + "source": "/delegation-toolkit/development/get-started/eip7702-quickstart/", + "destination": "/delegation-toolkit/development/get-started/smart-account-quickstart/eip7702/" + }, + { + "source": "/delegation-toolkit/development/get-started/cli-quickstart/", + "destination": "/delegation-toolkit/development/get-started/use-the-cli/" + }, { "source": "/developer-tools/faucet/sepolia/", "destination": "/developer-tools/faucet/"