From 59e84543dfccde7d9c19605fcc77df3c3df2195c Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Tue, 2 Dec 2025 11:28:03 +0400 Subject: [PATCH 1/7] add redelegation guide --- gator-sidebar.js | 1 + .../guides/delegation/create-redelegation.md | 146 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 smart-accounts-kit/guides/delegation/create-redelegation.md diff --git a/gator-sidebar.js b/gator-sidebar.js index 55ab4c96ffd..0d2bde0c3f3 100644 --- a/gator-sidebar.js +++ b/gator-sidebar.js @@ -79,6 +79,7 @@ const sidebar = { 'guides/delegation/use-delegation-scopes/constrain-scope', ], }, + 'guides/delegation/create-redelegation', 'guides/delegation/check-delegation-state', 'guides/delegation/disable-delegation', ], diff --git a/smart-accounts-kit/guides/delegation/create-redelegation.md b/smart-accounts-kit/guides/delegation/create-redelegation.md new file mode 100644 index 00000000000..cecacc7e405 --- /dev/null +++ b/smart-accounts-kit/guides/delegation/create-redelegation.md @@ -0,0 +1,146 @@ +--- +description: Learn how to create a redelegation. +sidebar_label: Create a redelegation +toc_max_heading_level: 3 +keywords: [delegation, state, caveat enforcer, delegation scope, redelegation] +--- + +import Tabs from "@theme/Tabs"; +import TabItem from "@theme/TabItem"; + +# Create a redelegation + +Redelegation is a core feature that sets Delegations apart from other permission sharing frameworks. +It allows a delegate to create a delegation chain, passing on the same or reduced level of authority +from the root delegator. + +For example, if Alice grants Bob permission to spend 10 USDC on her behalf, Bob can further grant Carol +permission to spend up to 5 USDC on Alice's behalf. This creates a delegation chain where the root +permissions are reshared with additional parties. + +## Prerequisites + +- [Install and set up the Smart Accounts Kit.](../../get-started/install.md) + +## Create a delegation + +Create a [root delegation](../../concepts/delegation/index.md#delegation-types) from Alice to Bob. + +This example uses the [`erc20TransferAmount`](use-delegation-scopes/spending-limit.md#erc-20-transfer-scope) scope, allowing +Alice to delegate to Bob the ability to spend 10 USDC on her behalf. + + + + +```typescript +import { aliceSmartAccount, bobSmartAccount } from "./config.ts"; +import { createDelegation } from '@metamask/smart-accounts-kit' +import { parseUnits } from 'viem' + +const delegation = createDelegation({ + scope: { + type: "erc20TransferAmount", + tokenAddress: "0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92", + // USDC has 6 decimal places. + maxAmount: parseUnits("10", 6), + }, + to: bobSmartAccount, + from: aliceSmartAccount, + environment: aliceSmartAccount.environment, +}) + +const signedDelegation = aliceSmartAccount.signDelegation({ delegation }) +``` + + + + +```typescript +import { Implementation, toMetaMaskSmartAccount } from "@metamask/smart-accounts-kit" +import { privateKeyToAccount } from "viem/accounts" +import { createPublicClient, http } from "viem" +import { sepolia as chain } from "viem/chains" + +const publicClient = createPublicClient({ + chain, + transport: http(), +}) + +const aliceAccount = privateKeyToAccount("0x...") +const bobAccount = privateKeyToAccount("0x...") + +export const aliceSmartAccount = await toMetaMaskSmartAccount({ + client: publicClient, + implementation: Implementation.Hybrid, + deployParams: [aliceAccount.address, [], [], []], + deploySalt: "0x", + signer: { account: aliceAccount }, +}) + +export const bobSmartAccount = await toMetaMaskSmartAccount({ + client: publicClient, + implementation: Implementation.Hybrid, + deployParams: [bobAccount.address, [], [], []], + deploySalt: "0x", + signer: { account: bobAccount }, +}) +``` + + + + +## Create a redelegation + +Create a [redelegation](../../concepts/delegation/index.md#delegation-types) from Bob to Carol. When creating a redelegation, you can only narrow the scope of the original authority, not expand it. + +This example uses the [`erc20TransferAmount`](use-delegation-scopes/spending-limit.md#erc-20-transfer-scope) scope, allowing +Bob to delegate to Carol the ability to spend 5 USDC on Alice's behalf. + + + + +```typescript +import { bobSmartAccount, carolSmartAccount } from "./config.ts" +import { createDelegation } from '@metamask/smart-accounts-kit' +import { parseUnits } from 'viem' + +const redelegation = createDelegation({ + scope: { + type: "erc20TransferAmount", + tokenAddress: "0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92", + // USDC has 6 decimal places. + maxAmount: parseUnits("5", 6), + }, + to: carolSmartAccount, + from: bobSmartAccount, + // Signed root delegation from previous step. + parentDelegation: signedDelegation, + environment: bobSmartAccount.environment, +}) + +const signedRedelegation = bobSmartAccount.signDelegation({ delegation: redelegation }) +``` + + + + +```typescript +// Update the existing config to create a smart account for Carol. + +const carolAccount = privateKeyToAccount("0x...") + +export const carolSmartAccount = await toMetaMaskSmartAccount({ + client: publicClient, + implementation: Implementation.Hybrid, + deployParams: [carolAccount.address, [], [], []], + deploySalt: "0x", + signer: { account: carolAccount }, +}) +``` + + + + +## Next steps + +- See [how to disable a delegation](disable-delegation.md) to revoke permissions. \ No newline at end of file From 4787e68ddb2a3d2c769c12144346ed7bd5fa3972 Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Tue, 2 Dec 2025 22:16:02 +0400 Subject: [PATCH 2/7] minor fixes --- .../guides/delegation/create-redelegation.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/smart-accounts-kit/guides/delegation/create-redelegation.md b/smart-accounts-kit/guides/delegation/create-redelegation.md index cecacc7e405..e64e3fd7871 100644 --- a/smart-accounts-kit/guides/delegation/create-redelegation.md +++ b/smart-accounts-kit/guides/delegation/create-redelegation.md @@ -10,7 +10,7 @@ import TabItem from "@theme/TabItem"; # Create a redelegation -Redelegation is a core feature that sets Delegations apart from other permission sharing frameworks. +Redelegation is a core feature that sets delegations apart from other permission sharing frameworks. It allows a delegate to create a delegation chain, passing on the same or reduced level of authority from the root delegator. @@ -44,8 +44,8 @@ const delegation = createDelegation({ // USDC has 6 decimal places. maxAmount: parseUnits("10", 6), }, - to: bobSmartAccount, - from: aliceSmartAccount, + to: bobSmartAccount.address, + from: aliceSmartAccount.address, environment: aliceSmartAccount.environment, }) @@ -111,8 +111,8 @@ const redelegation = createDelegation({ // USDC has 6 decimal places. maxAmount: parseUnits("5", 6), }, - to: carolSmartAccount, - from: bobSmartAccount, + to: carolSmartAccoun.address, + from: bobSmartAccount.address, // Signed root delegation from previous step. parentDelegation: signedDelegation, environment: bobSmartAccount.environment, From 3ad58a93bb574dff5010c7ef989fb3f6fa7e73bc Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Tue, 2 Dec 2025 22:25:34 +0400 Subject: [PATCH 3/7] minor fix --- smart-accounts-kit/guides/delegation/create-redelegation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smart-accounts-kit/guides/delegation/create-redelegation.md b/smart-accounts-kit/guides/delegation/create-redelegation.md index e64e3fd7871..d37206d56ce 100644 --- a/smart-accounts-kit/guides/delegation/create-redelegation.md +++ b/smart-accounts-kit/guides/delegation/create-redelegation.md @@ -15,8 +15,8 @@ It allows a delegate to create a delegation chain, passing on the same or reduce from the root delegator. For example, if Alice grants Bob permission to spend 10 USDC on her behalf, Bob can further grant Carol -permission to spend up to 5 USDC on Alice's behalf. This creates a delegation chain where the root -permissions are reshared with additional parties. +permission to spend up to 5 USDC on Alice's behalf-that is, Bob can redelegate. This creates a delegation +chain where the root permissions are reshared with additional parties. ## Prerequisites From 560ffa7b718ae4ca6dd7d8d8be4f02ab9e2f7615 Mon Sep 17 00:00:00 2001 From: AyushBherwani1998 Date: Wed, 3 Dec 2025 08:12:55 +0400 Subject: [PATCH 4/7] improve guide --- smart-accounts-kit/guides/delegation/create-redelegation.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/smart-accounts-kit/guides/delegation/create-redelegation.md b/smart-accounts-kit/guides/delegation/create-redelegation.md index d37206d56ce..1e78b1a29a2 100644 --- a/smart-accounts-kit/guides/delegation/create-redelegation.md +++ b/smart-accounts-kit/guides/delegation/create-redelegation.md @@ -21,6 +21,7 @@ chain where the root permissions are reshared with additional parties. ## Prerequisites - [Install and set up the Smart Accounts Kit.](../../get-started/install.md) +- [Learn how to create a delegation.](execute-on-smart-accounts-behalf.md) ## Create a delegation @@ -93,8 +94,9 @@ export const bobSmartAccount = await toMetaMaskSmartAccount({ Create a [redelegation](../../concepts/delegation/index.md#delegation-types) from Bob to Carol. When creating a redelegation, you can only narrow the scope of the original authority, not expand it. +To create a redelegation, provide the signed delegation as the `parentDelegation` argument when calling [createDelegation](../../reference/delegation/index.md#createdelegation). This example uses the [`erc20TransferAmount`](use-delegation-scopes/spending-limit.md#erc-20-transfer-scope) scope, allowing -Bob to delegate to Carol the ability to spend 5 USDC on Alice's behalf. +Bob to delegate to Carol the ability to spend 5 USDC on Alice's behalf. From 3802fb863c5e1610ec4666d6b90114fd8eb05d5f Mon Sep 17 00:00:00 2001 From: m4sterbunny Date: Wed, 3 Dec 2025 08:19:50 +0000 Subject: [PATCH 5/7] Update smart-accounts-kit/guides/delegation/create-redelegation.md --- smart-accounts-kit/guides/delegation/create-redelegation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smart-accounts-kit/guides/delegation/create-redelegation.md b/smart-accounts-kit/guides/delegation/create-redelegation.md index 1e78b1a29a2..05720612121 100644 --- a/smart-accounts-kit/guides/delegation/create-redelegation.md +++ b/smart-accounts-kit/guides/delegation/create-redelegation.md @@ -20,7 +20,7 @@ chain where the root permissions are reshared with additional parties. ## Prerequisites -- [Install and set up the Smart Accounts Kit.](../../get-started/install.md) +- [Install and set up the Smart Accounts Kit](../../get-started/install.md). - [Learn how to create a delegation.](execute-on-smart-accounts-behalf.md) ## Create a delegation From 53dcf8d14c7e8eb81fcd8b4feb03ce5a89e013b0 Mon Sep 17 00:00:00 2001 From: m4sterbunny Date: Wed, 3 Dec 2025 08:19:59 +0000 Subject: [PATCH 6/7] Update smart-accounts-kit/guides/delegation/create-redelegation.md --- smart-accounts-kit/guides/delegation/create-redelegation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smart-accounts-kit/guides/delegation/create-redelegation.md b/smart-accounts-kit/guides/delegation/create-redelegation.md index 05720612121..c8a2be701ae 100644 --- a/smart-accounts-kit/guides/delegation/create-redelegation.md +++ b/smart-accounts-kit/guides/delegation/create-redelegation.md @@ -21,7 +21,7 @@ chain where the root permissions are reshared with additional parties. ## Prerequisites - [Install and set up the Smart Accounts Kit](../../get-started/install.md). -- [Learn how to create a delegation.](execute-on-smart-accounts-behalf.md) +- [Learn how to create a delegation](execute-on-smart-accounts-behalf.md). ## Create a delegation From 80afd49627c6a7631749d9e47c06b7962663ce65 Mon Sep 17 00:00:00 2001 From: m4sterbunny Date: Wed, 3 Dec 2025 08:21:39 +0000 Subject: [PATCH 7/7] Update smart-accounts-kit/guides/delegation/create-redelegation.md --- smart-accounts-kit/guides/delegation/create-redelegation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smart-accounts-kit/guides/delegation/create-redelegation.md b/smart-accounts-kit/guides/delegation/create-redelegation.md index c8a2be701ae..e02bbab5aee 100644 --- a/smart-accounts-kit/guides/delegation/create-redelegation.md +++ b/smart-accounts-kit/guides/delegation/create-redelegation.md @@ -113,7 +113,7 @@ const redelegation = createDelegation({ // USDC has 6 decimal places. maxAmount: parseUnits("5", 6), }, - to: carolSmartAccoun.address, + to: carolSmartAccount.address, from: bobSmartAccount.address, // Signed root delegation from previous step. parentDelegation: signedDelegation,