Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,50 @@ const sessionAccount = privateKeyToAccount("0x...");
</TabItem>
</Tabs>

### 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 handle the upgrade [programmatically](/wallet/how-to/send-transactions/send-batch-transactions/#about-atomic-batch-transactions) or ask the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you specifically need to do to handle the upgrade programmatically? This links to the wallet api send batch txns page – but is it also possible through the SDK tutorial or the DTK 7702 quickstart?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to initiate the wallet_sendCalls (ERC-5792) request. This can’t be done through the DTK 7702 Quickstart, as that guide focuses on upgrading embedded accounts to MetaMask Smart Accounts. Instead, it can be achieved using the SDK tutorial, but the two guides aren’t fully aligned.

In the SDK tutorial, you’ll use Wagmi, connect the wallet, and then interact through hooks. The Wallet API documentation, on the other hand, focuses on using the provider, which you can obtain directly from the WalletClient created earlier, allowing you to follow a single, streamlined flow without needing the extra steps described in the SDK tutorial.

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 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
import { getDeleGatorEnvironment } from "@metamask/delegation-toolkit";
import { sepolia as chain } from "viem/chains";

const addresses = await walletClient.requestAddresses();
const address = addresses[0];

// Get the EOA account code
const code = await publicClient.getCode({
address,
});

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)}`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Delegation Prefix Validation Missing

The logic for checking EOA account code extracts the delegator address using substring(8) without first validating if the code starts with the EIP-7702 delegation prefix (0xef0100). This can lead to incorrect delegation detection and misidentification of account upgrade status.

Additional Locations (1)

Fix in Cursor Fix in Web


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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Incomplete Account Upgrade Handling

The isAccountUpgraded variable is computed but unused, making the account upgrade check incomplete. The guide describes handling both upgraded and non-upgraded accounts, but the code doesn't demonstrate this conditional logic.

Additional Locations (1)

Fix in Cursor Fix in Web

}
```

### 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
Expand Down Expand Up @@ -137,7 +180,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.

Expand Down Expand Up @@ -184,7 +227,7 @@ const sessionAccountWalletClient = createWalletClient({
</Tabs>


### 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,50 @@ const sessionAccount = privateKeyToAccount("0x...");
</TabItem>
</Tabs>

### 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 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 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
import { getDeleGatorEnvironment } from "@metamask/delegation-toolkit";
import { sepolia as chain } from "viem/chains";

const addresses = await walletClient.requestAddresses();
const address = addresses[0];

// Get the EOA account code
const code = await publicClient.getCode({
address,
});

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

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
Expand Down Expand Up @@ -137,7 +180,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.

Expand Down Expand Up @@ -184,7 +227,7 @@ const sessionAccountWalletClient = createWalletClient({
</Tabs>


### 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.

Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading