From c34e27c554345ca801ed1c4f1298bce1377ff29b Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Fri, 24 Oct 2025 02:02:59 +0400 Subject: [PATCH 1/3] improve 7715 guide --- .../execute-on-metamask-users-behalf.md | 44 +++++++++++++++++-- .../execute-on-metamask-users-behalf.md | 44 +++++++++++++++++-- package-lock.json | 6 --- 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md b/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md index 355fa1a523b..00ff3a967e0 100644 --- a/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md +++ b/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md @@ -95,7 +95,45 @@ const sessionAccount = privateKeyToAccount("0x..."); -### 4. Request ERC-7715 permissions +### 4. Check the EOA account code + +Currently, ERC-7715 does not support automatically upgrading a user’s account to a [MetaMask smart account](../../concepts/smart-accounts.md). Therefore, you must +ensure that the user is upgraded to a smart account before requesting ERC-7715 permissions. + +If the user has not yet been upgraded, you can either handle the upgrade [programmatically](https://docs.metamask.io/wallet/how-to/send-transactions/send-batch-transactions#about-atomic-batch-transactions) or ask the +user to [switch to a smart account manually.](https://support.metamask.io/configure/accounts/switch-to-or-revert-from-a-smart-account/#how-to-switch-to-a-metamask-smart-account). + +:::info Why Smart Account upgrade is required? +MetaMask's ERC-7715 implementation requires the MetaMask user to be upgraded to a MetaMask +smart account, as ERC-7715 permission requests signature for[ ERC-7710 delegation](../../concepts/delegation/index.md) under +the hood. ERC-7710 delegation is one of the core feature supported only by MetaMask Smart Accounts. +::: + +```typescript +import { getDeleGatorEnvironment } from "@metamask/delegation-toolkit"; + +const addresses = await walletClient.requestAddresses(); +const address = addresses[0]; + +// Get the EOA account code +const code = await publicClient.getCode({ + address, +}); + +// The address to which EOA has delegated. According to EIP-7702, 0xef0100 || address +// represents the delegation. +// +// You need to remove the first 8 characters (0xef0100) to get the delegator address. +const delegatorAddress = `0x${code?.substring(8)}`; + +const statelessDelegatorAddress = getDeleGatorEnvironment(sepolia.id).implementations.EIP7702StatelessDeleGatorImpl; + +// If account is not upgraded to MetaMask smart account, you can +// either upgrade programmatically or ask the user to switch to a smart account manually. +const isAccountUpgraded = delegatorAddress.toLowerCase() === statelessDelegatorAddress.toLowerCase(); +``` + +### 5. Request ERC-7715 permissions Request ERC-7715 permissions from the user. In this example, you'll request an [ERC-20 periodic permission](use-permissions/erc20-token.md#erc-20-periodic-permission) using the Wallet Client's @@ -137,7 +175,7 @@ const grantedPermissions = await walletClient.requestExecutionPermissions([{ }]); ``` -### 5. Set up a Viem client +### 6. Set up a Viem client Set up a Viem client depending on your session account type. @@ -184,7 +222,7 @@ const sessionAccountWalletClient = createWalletClient({ -### 6. Redeem ERC-7715 permissions +### 7. Redeem ERC-7715 permissions The session account can now redeem the permissions. The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on the user's behalf. diff --git a/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md b/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md index 355fa1a523b..00ff3a967e0 100644 --- a/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md +++ b/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md @@ -95,7 +95,45 @@ const sessionAccount = privateKeyToAccount("0x..."); -### 4. Request ERC-7715 permissions +### 4. Check the EOA account code + +Currently, ERC-7715 does not support automatically upgrading a user’s account to a [MetaMask smart account](../../concepts/smart-accounts.md). Therefore, you must +ensure that the user is upgraded to a smart account before requesting ERC-7715 permissions. + +If the user has not yet been upgraded, you can either handle the upgrade [programmatically](https://docs.metamask.io/wallet/how-to/send-transactions/send-batch-transactions#about-atomic-batch-transactions) or ask the +user to [switch to a smart account manually.](https://support.metamask.io/configure/accounts/switch-to-or-revert-from-a-smart-account/#how-to-switch-to-a-metamask-smart-account). + +:::info Why Smart Account upgrade is required? +MetaMask's ERC-7715 implementation requires the MetaMask user to be upgraded to a MetaMask +smart account, as ERC-7715 permission requests signature for[ ERC-7710 delegation](../../concepts/delegation/index.md) under +the hood. ERC-7710 delegation is one of the core feature supported only by MetaMask Smart Accounts. +::: + +```typescript +import { getDeleGatorEnvironment } from "@metamask/delegation-toolkit"; + +const addresses = await walletClient.requestAddresses(); +const address = addresses[0]; + +// Get the EOA account code +const code = await publicClient.getCode({ + address, +}); + +// The address to which EOA has delegated. According to EIP-7702, 0xef0100 || address +// represents the delegation. +// +// You need to remove the first 8 characters (0xef0100) to get the delegator address. +const delegatorAddress = `0x${code?.substring(8)}`; + +const statelessDelegatorAddress = getDeleGatorEnvironment(sepolia.id).implementations.EIP7702StatelessDeleGatorImpl; + +// If account is not upgraded to MetaMask smart account, you can +// either upgrade programmatically or ask the user to switch to a smart account manually. +const isAccountUpgraded = delegatorAddress.toLowerCase() === statelessDelegatorAddress.toLowerCase(); +``` + +### 5. Request ERC-7715 permissions Request ERC-7715 permissions from the user. In this example, you'll request an [ERC-20 periodic permission](use-permissions/erc20-token.md#erc-20-periodic-permission) using the Wallet Client's @@ -137,7 +175,7 @@ const grantedPermissions = await walletClient.requestExecutionPermissions([{ }]); ``` -### 5. Set up a Viem client +### 6. Set up a Viem client Set up a Viem client depending on your session account type. @@ -184,7 +222,7 @@ const sessionAccountWalletClient = createWalletClient({ -### 6. Redeem ERC-7715 permissions +### 7. Redeem ERC-7715 permissions The session account can now redeem the permissions. The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on the user's behalf. diff --git a/package-lock.json b/package-lock.json index e5bc792efbd..a17b47386de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12587,12 +12587,6 @@ "version": "1.0.2", "license": "MIT" }, - "node_modules/bare-events": { - "version": "2.5.4", - "license": "Apache-2.0", - "optional": true, - "peer": true - }, "node_modules/base-x": { "version": "3.0.11", "license": "MIT", From 611244e5731a6e9d81dd650294ece409adee1043 Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Fri, 24 Oct 2025 02:12:19 +0400 Subject: [PATCH 2/3] resolve cursor comments --- .../execute-on-metamask-users-behalf.md | 27 +++++++++++-------- .../execute-on-metamask-users-behalf.md | 27 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md b/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md index 00ff3a967e0..a17d9cf33a7 100644 --- a/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md +++ b/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md @@ -111,6 +111,7 @@ the hood. ERC-7710 delegation is one of the core feature supported only by MetaM ```typescript import { getDeleGatorEnvironment } from "@metamask/delegation-toolkit"; +import { sepolia as chain } from "viem/chains"; const addresses = await walletClient.requestAddresses(); const address = addresses[0]; @@ -120,17 +121,21 @@ const code = await publicClient.getCode({ address, }); -// The address to which EOA has delegated. According to EIP-7702, 0xef0100 || address -// represents the delegation. -// -// You need to remove the first 8 characters (0xef0100) to get the delegator address. -const delegatorAddress = `0x${code?.substring(8)}`; - -const statelessDelegatorAddress = getDeleGatorEnvironment(sepolia.id).implementations.EIP7702StatelessDeleGatorImpl; - -// If account is not upgraded to MetaMask smart account, you can -// either upgrade programmatically or ask the user to switch to a smart account manually. -const isAccountUpgraded = delegatorAddress.toLowerCase() === statelessDelegatorAddress.toLowerCase(); +if (code) { + // The address to which EOA has delegated. According to EIP-7702, 0xef0100 || address + // represents the delegation. + // + // You need to remove the first 8 characters (0xef0100) to get the delegator address. + const delegatorAddress = `0x${code.substring(8)}`; + + const statelessDelegatorAddress = getDeleGatorEnvironment(chain.id) + .implementations + .EIP7702StatelessDeleGatorImpl; + + // If account is not upgraded to MetaMask smart account, you can + // either upgrade programmatically or ask the user to switch to a smart account manually. + const isAccountUpgraded = delegatorAddress.toLowerCase() === statelessDelegatorAddress.toLowerCase(); +} ``` ### 5. Request ERC-7715 permissions diff --git a/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md b/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md index 00ff3a967e0..a17d9cf33a7 100644 --- a/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md +++ b/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md @@ -111,6 +111,7 @@ the hood. ERC-7710 delegation is one of the core feature supported only by MetaM ```typescript import { getDeleGatorEnvironment } from "@metamask/delegation-toolkit"; +import { sepolia as chain } from "viem/chains"; const addresses = await walletClient.requestAddresses(); const address = addresses[0]; @@ -120,17 +121,21 @@ const code = await publicClient.getCode({ address, }); -// The address to which EOA has delegated. According to EIP-7702, 0xef0100 || address -// represents the delegation. -// -// You need to remove the first 8 characters (0xef0100) to get the delegator address. -const delegatorAddress = `0x${code?.substring(8)}`; - -const statelessDelegatorAddress = getDeleGatorEnvironment(sepolia.id).implementations.EIP7702StatelessDeleGatorImpl; - -// If account is not upgraded to MetaMask smart account, you can -// either upgrade programmatically or ask the user to switch to a smart account manually. -const isAccountUpgraded = delegatorAddress.toLowerCase() === statelessDelegatorAddress.toLowerCase(); +if (code) { + // The address to which EOA has delegated. According to EIP-7702, 0xef0100 || address + // represents the delegation. + // + // You need to remove the first 8 characters (0xef0100) to get the delegator address. + const delegatorAddress = `0x${code.substring(8)}`; + + const statelessDelegatorAddress = getDeleGatorEnvironment(chain.id) + .implementations + .EIP7702StatelessDeleGatorImpl; + + // If account is not upgraded to MetaMask smart account, you can + // either upgrade programmatically or ask the user to switch to a smart account manually. + const isAccountUpgraded = delegatorAddress.toLowerCase() === statelessDelegatorAddress.toLowerCase(); +} ``` ### 5. Request ERC-7715 permissions From 3fce3117eca70cbd2d384325b715e5f6225695a3 Mon Sep 17 00:00:00 2001 From: Alexandra Carrillo Date: Thu, 23 Oct 2025 17:43:52 -0700 Subject: [PATCH 3/3] edits --- .../erc7715/execute-on-metamask-users-behalf.md | 14 +++++++------- .../erc7715/execute-on-metamask-users-behalf.md | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md b/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md index a17d9cf33a7..8386d747a8d 100644 --- a/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md +++ b/delegation-toolkit/guides/erc7715/execute-on-metamask-users-behalf.md @@ -97,16 +97,16 @@ const sessionAccount = privateKeyToAccount("0x..."); ### 4. Check the EOA account code -Currently, ERC-7715 does not support automatically upgrading a user’s account to a [MetaMask smart account](../../concepts/smart-accounts.md). Therefore, you must +Currently, ERC-7715 does not support automatically upgrading a user's account to a [MetaMask smart account](../../concepts/smart-accounts.md). Therefore, you must ensure that the user is upgraded to a smart account before requesting ERC-7715 permissions. -If the user has not yet been upgraded, you can either handle the upgrade [programmatically](https://docs.metamask.io/wallet/how-to/send-transactions/send-batch-transactions#about-atomic-batch-transactions) or ask the -user to [switch to a smart account manually.](https://support.metamask.io/configure/accounts/switch-to-or-revert-from-a-smart-account/#how-to-switch-to-a-metamask-smart-account). +If the user has not yet been upgraded, you can handle the upgrade [programmatically](/wallet/how-to/send-transactions/send-batch-transactions/#about-atomic-batch-transactions) or ask the +user to [switch to a smart account manually](https://support.metamask.io/configure/accounts/switch-to-or-revert-from-a-smart-account/#how-to-switch-to-a-metamask-smart-account). -:::info Why Smart Account upgrade is required? -MetaMask's ERC-7715 implementation requires the MetaMask user to be upgraded to a MetaMask -smart account, as ERC-7715 permission requests signature for[ ERC-7710 delegation](../../concepts/delegation/index.md) under -the hood. ERC-7710 delegation is one of the core feature supported only by MetaMask Smart Accounts. +:::info Why is a Smart Account upgrade is required? +MetaMask's ERC-7715 implementation requires the user to be upgraded to a MetaMask +Smart Account because, under the hood, you're requesting a signature for an [ERC-7710 delegation](../../concepts/delegation/index.md). +ERC-7710 delegation is one of the core features supported only by MetaMask Smart Accounts. ::: ```typescript diff --git a/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md b/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md index a17d9cf33a7..8386d747a8d 100644 --- a/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md +++ b/gator_versioned_docs/version-0.13.0/guides/erc7715/execute-on-metamask-users-behalf.md @@ -97,16 +97,16 @@ const sessionAccount = privateKeyToAccount("0x..."); ### 4. Check the EOA account code -Currently, ERC-7715 does not support automatically upgrading a user’s account to a [MetaMask smart account](../../concepts/smart-accounts.md). Therefore, you must +Currently, ERC-7715 does not support automatically upgrading a user's account to a [MetaMask smart account](../../concepts/smart-accounts.md). Therefore, you must ensure that the user is upgraded to a smart account before requesting ERC-7715 permissions. -If the user has not yet been upgraded, you can either handle the upgrade [programmatically](https://docs.metamask.io/wallet/how-to/send-transactions/send-batch-transactions#about-atomic-batch-transactions) or ask the -user to [switch to a smart account manually.](https://support.metamask.io/configure/accounts/switch-to-or-revert-from-a-smart-account/#how-to-switch-to-a-metamask-smart-account). +If the user has not yet been upgraded, you can handle the upgrade [programmatically](/wallet/how-to/send-transactions/send-batch-transactions/#about-atomic-batch-transactions) or ask the +user to [switch to a smart account manually](https://support.metamask.io/configure/accounts/switch-to-or-revert-from-a-smart-account/#how-to-switch-to-a-metamask-smart-account). -:::info Why Smart Account upgrade is required? -MetaMask's ERC-7715 implementation requires the MetaMask user to be upgraded to a MetaMask -smart account, as ERC-7715 permission requests signature for[ ERC-7710 delegation](../../concepts/delegation/index.md) under -the hood. ERC-7710 delegation is one of the core feature supported only by MetaMask Smart Accounts. +:::info Why is a Smart Account upgrade is required? +MetaMask's ERC-7715 implementation requires the user to be upgraded to a MetaMask +Smart Account because, under the hood, you're requesting a signature for an [ERC-7710 delegation](../../concepts/delegation/index.md). +ERC-7710 delegation is one of the core features supported only by MetaMask Smart Accounts. ::: ```typescript