Skip to content
Merged
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
26 changes: 18 additions & 8 deletions delegation-toolkit/get-started/erc7715-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ 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 [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later.
- Install [Yarn](https://yarnpkg.com/),
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager.
- [Install MetaMask Flask 12.14.2 or later](/snaps/get-started/install-flask).

## Steps

### 1. Set up a Wallet Client
### 1. Install the toolkit

Install the [MetaMask Delegation Toolkit](https://www.npmjs.com/package/@metamask/delegation-toolkit):

```bash npm2yarn
npm install @metamask/delegation-toolkit
```

### 2. Set up a Wallet Client

Set up a [Viem Wallet Client](https://viem.sh/docs/clients/wallet) using Viem's `createWalletClient` function. This client will help you interact with MetaMask Flask.

Expand All @@ -32,7 +42,7 @@ const walletClient = createWalletClient({
}).extend(erc7715ProviderActions());
```

### 2. Set up a Public Client
### 3. 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 help you query the account state and interact with blockchain networks.
Expand All @@ -47,7 +57,7 @@ const publicClient = createPublicClient({
});
```

### 3. Set up a session account
### 4. Set up a session account

Set up a session account which can either be a smart account or an externally owned
account (EOA) to request ERC-7715 permissions. This account is responsible
Expand All @@ -74,7 +84,7 @@ const sessionAccount = await toMetaMaskSmartAccount({
});
```

### 4. Request ERC-7715 permissions
### 5. Request ERC-7715 permissions

Request ERC-7715 permissions from the user. Currently, only the
`native-token-stream` permission type is supported, which allows the dapp to stream
Expand Down Expand Up @@ -106,7 +116,7 @@ const grantedPermissions = await walletClient.grantPermissions([{
}]);
```

### 5. Set up a Bundler Client
### 6. 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
Expand All @@ -127,7 +137,7 @@ const bundlerClient = createBundlerClient({
}).extend(erc7710BundlerActions());
```

### 6. Redeem ERC-7715 permissions
### 7. Redeem ERC-7715 permissions

The session account can now [redeem the delegation](../experimental/erc-7710-redeem-delegations.md). The redeem transaction is sent to the `DelegationManager` contract, which validates the delegation and executes actions on the user's behalf.

Expand Down
2 changes: 1 addition & 1 deletion delegation-toolkit/get-started/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This page provides instructions to install and set up the MetaMask Delegation To

### 1. Install the toolkit

Install the [MetaMask Delegation Toolkit](https://github.com/MetaMask/delegation-toolkit) dependencies:
Install the [MetaMask Delegation Toolkit](https://www.npmjs.com/package/@metamask/delegation-toolkit):

```bash npm2yarn
npm install @metamask/delegation-toolkit
Expand Down
28 changes: 19 additions & 9 deletions delegation-toolkit/get-started/smart-account-quickstart/eip7702.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ abstraction, such as batch transactions, gas sponsorship, and [delegation capabi

## Prerequisites

- [Install and set up the Delegation Toolkit.](../install.md)
- [Install Viem.](https://viem.sh/)
- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later.
- Install [Yarn](https://yarnpkg.com/),
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager.
- [Install Viem](https://viem.sh/).

## Steps

### 1. Set up a Public Client
### 1. Install the toolkit

Install the [MetaMask Delegation Toolkit](https://www.npmjs.com/package/@metamask/delegation-toolkit):

```bash npm2yarn
npm install @metamask/delegation-toolkit
```

### 2. 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 EOA query the account state and interact with blockchain network.
Expand All @@ -31,7 +41,7 @@ const publicClient = createPublicClient({
});
```

### 2. Set up a Bundler Client
### 3. 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.
Expand All @@ -45,7 +55,7 @@ const bundlerClient = createBundlerClient({
});
```

### 3. Set up a Wallet Client
### 4. Set up a Wallet Client

Set up [Viem Wallet Client](https://viem.sh/docs/clients/wallet) using Viem's `createWalletClient` function.
This lets you sign and submit EIP-7702 authorization.
Expand All @@ -64,7 +74,7 @@ export const walletClient = createWalletClient({
});
```

### 4. Authorize a 7702 delegation
### 5. Authorize a 7702 delegation

Create an authorization to map the contract code to an EOA, and sign it
using Viem's [`signAuthorization`](https://viem.sh/docs/eip7702/signAuthorization) action. The `signAuthorization` action
Expand Down Expand Up @@ -92,7 +102,7 @@ const authorization = await walletClient.signAuthorization({
});
```

### 5. Submit the authorization
### 6. Submit the authorization

Once you have signed an authorization, you can send an EIP-7702 transaction to set the EOA code.
Since the authorization cannot be sent by itself, you can include it alongside a dummy transaction.
Expand All @@ -107,7 +117,7 @@ const hash = await walletClient.sendTransaction({
});
```

### 6. Create a MetaMask smart account
### 7. Create a MetaMask smart account

Create a smart account instance for the EOA and start
leveraging the benefits of account abstraction.
Expand All @@ -129,7 +139,7 @@ const smartAccount = await toMetaMaskSmartAccount({
});
```

### 7. Send a user operation
### 8. Send a user operation

Send a user operation through the upgraded EOA, using Viem's [`sendUserOperation`](https://viem.sh/account-abstraction/actions/bundler/sendUserOperation) method.

Expand Down
20 changes: 15 additions & 5 deletions delegation-toolkit/get-started/smart-account-quickstart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ You can get started quickly with [MetaMask Smart Accounts](../../concepts/smart-

## Prerequisites

[Install and set up the Delegation Toolkit.](../install.md)
- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later.
- Install [Yarn](https://yarnpkg.com/),
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager.

## Steps

### 1. Set up a Public Client
### 1. Install the toolkit

Install the [MetaMask Delegation Toolkit](https://www.npmjs.com/package/@metamask/delegation-toolkit):

```bash npm2yarn
npm install @metamask/delegation-toolkit
```

### 2. 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 smart account query the signer's account state and interact with blockchain network.

Expand All @@ -27,7 +37,7 @@ const publicClient = createPublicClient({
});
```

### 2. Set up a Bundler Client
### 3. 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.

Expand All @@ -40,7 +50,7 @@ const bundlerClient = createBundlerClient({
});
```

### 3. Create a MetaMask smart account
### 4. Create a MetaMask smart account

[Create a MetaMask smart account](../../guides/smart-accounts/create-smart-account.md) to send the first user operation.

Expand All @@ -62,7 +72,7 @@ const smartAccount = await toMetaMaskSmartAccount({
});
```

### 4. Send a user operation
### 5. Send a user operation

Send a user operation using Viem's [`sendUserOperation`](https://viem.sh/account-abstraction/actions/bundler/sendUserOperation) method.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ export const delegateWalletClient = createWalletClient({
Create a [root delegation](../../concepts/delegation/index.md#delegation-types) from Alice to Bob.
With a root delegation, Alice is delegating her own authority away, as opposed to *redelegating* permissions she received from a previous delegation.

Use the toolkit's [`createDelegation`](../../reference/api/delegation.md#createdelegation) method to create a root delegation.
This example passes an empty `caveats` array, which means Bob can perform any action on Alice's behalf. We recommend [restricting the 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.
Use the toolkit's [`createDelegation`](../../reference/api/delegation.md#createdelegation) method to create a root delegation. When creating
delegation, you need to configure the scope of the delegation to define the initial authority.

This example uses the [`erc20TransferAmount`](./use-delegation-scopes/spending-limit#erc-20-transfer-scope) scope, allowing Alice to delegate to Bob the ability to spend her USDC, with a
specified limit on the total amount.

:::warning Important

Expand All @@ -135,10 +137,18 @@ Before creating a delegation, ensure that the delegator account (in this example
```typescript
import { createDelegation } from "@metamask/delegation-toolkit"

// USDC address on Ethereum Sepolia.
const tokenAddress = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238";

const delegation = createDelegation({
to: delegateSmartAccount.address, // This example uses a delegate smart account
from: delegatorSmartAccount.address,
caveats: [], // Empty caveats array - we recommend adding appropriate restrictions.
environment: delegatorSmartAccount.environment
scope: {
type: "erc20TransferAmount",
tokenAddress,
maxAmount: 10000000n,
},
})
```

Expand Down Expand Up @@ -226,3 +236,8 @@ const transactionHash = await delegateWalletClient.sendTransaction({

</TabItem>
</Tabs>

## Next steps

- See [how to configure different scopes](use-delegation-scopes/index.md) to define the initial authority of a delegation.
- See [how to further refine the authority of a delegation](use-delegation-scopes/refine-scope.md) using caveat enforcers.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const delegation = createDelegation({
},
to: delegateAccount,
from: delegatorAccount,
environment: delegatorAccount.environment,
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const delegation = createDelegation({
},
to: delegateAccount,
from: delegatorAccount,
environment: delegatorAccount.environment,
Copy link

Choose a reason for hiding this comment

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

Bug: Incorrect Smart Account Property Access

The createDelegation examples incorrectly access delegatorAccount.environment. The environment property is specific to smart accounts, but delegatorAccount is typically an EOA and lacks this property. This pattern appears in several scope examples throughout the guides.

Additional Locations (2)

Fix in Cursor Fix in Web

});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const delegation = createDelegation({
},
to: delegateAccount,
from: delegatorAccount,
environment: delegatorAccount.environment,
});
```

Expand Down Expand Up @@ -67,6 +68,7 @@ const delegation = createDelegation({
},
to: delegateAccount,
from: delegatorAccount,
environment: delegatorAccount.environment,
});
```

Expand All @@ -92,6 +94,7 @@ const delegation = createDelegation({
},
to: delegateAccount,
from: delegatorAccount,
environment: delegatorAccount.environment,
});
```

Expand All @@ -113,6 +116,7 @@ const delegation = createDelegation({
},
to: delegateAccount,
from: delegatorAccount,
environment: delegatorAccount.environment,
});
```

Expand Down Expand Up @@ -140,6 +144,7 @@ const delegation = createDelegation({
},
to: delegateAccount,
from: delegatorAccount,
environment: delegatorAccount.environment,
});
```

Expand Down Expand Up @@ -167,6 +172,7 @@ const delegation = createDelegation({
},
to: delegateAccount,
from: delegatorAccount,
environment: delegatorAccount.environment,
});
```

Expand All @@ -187,10 +193,12 @@ import { createDelegation } from "@metamask/delegation-toolkit";
const delegation = createDelegation({
scope: {
type: "nativeTokenTransferAmount",
maxAmount: 1000000n,
// 0.001 ETH in wei format.
maxAmount: 1000000000000000n,
},
to: delegateAccount,
from: delegatorAccount,
environment: delegatorAccount.environment,
});
```

Expand Down
Loading