Skip to content

Add DTK tutorial for creating an invite link#2289

Merged
alexandratran merged 21 commits intofeat/v0.13-devfrom
2209-referral-link-tutorial
Sep 15, 2025
Merged

Add DTK tutorial for creating an invite link#2289
alexandratran merged 21 commits intofeat/v0.13-devfrom
2209-referral-link-tutorial

Conversation

@alexandratran
Copy link
Contributor

@alexandratran alexandratran commented Sep 9, 2025

Description

Add DTK tutorial for creating an invite link.

Issue(s) fixed

Fixes #2209

Preview

https://metamask-docs-i5mlyvk77-consensys-ddffed67.vercel.app/tutorials/create-invite-link/

Checklist

  • If this PR updates or adds documentation content that changes or adds technical meaning, it has received an approval from an engineer or DevRel from the relevant team.
  • If this PR updates or adds documentation content, it has received an approval from a technical writer.

AyushBherwani1998 and others added 3 commits September 8, 2025 22:27
Co-authored-by: AyushBherwani1998 <“ayush.bherwani1998@gmail.com”>
useSDK is now modified and connect, terminate options have moved to sdk object inside useSDK function

Co-authored-by: Mohammad Shahbaz Alam <shahbaz17@users.noreply.github.com>
@vercel
Copy link

vercel bot commented Sep 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
metamask-docs Ready Ready Preview Comment Sep 15, 2025 0:33am

bgravenorst and others added 6 commits September 10, 2025 06:55
Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
* Edit the React builder component.

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

* Typo.

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

---------

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
@alexandratran alexandratran marked this pull request as ready for review September 10, 2025 21:51
@alexandratran alexandratran requested review from a team as code owners September 10, 2025 21:51
alexandratran and others added 6 commits September 10, 2025 14:53
useSDK is now modified and connect, terminate options have moved to sdk object inside useSDK function

Co-authored-by: Mohammad Shahbaz Alam <shahbaz17@users.noreply.github.com>
Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
* Edit the React builder component.

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

* Typo.

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

---------

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
…amask-docs into 2209-referral-link-tutorial

# Conflicts:
#	src/pages/tutorials/create-custom-caveat-enforcer.md
@alexandratran alexandratran changed the base branch from main to feat/v0.13-dev September 10, 2025 22:03
Copy link
Contributor

@bgravenorst bgravenorst left a comment

Choose a reason for hiding this comment

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

LGTM, some minor feedback added.

import { Implementation, toMetaMaskSmartAccount } from '@metamask/delegation-toolkit';
import { privateKeyToAccount } from 'viem/accounts';

const account = privateKeyToAccount('0x...');
Copy link
Member

Choose a reason for hiding this comment

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

This should use wagmi hooks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Question: do we still need to create the Viem Public Client in Step 2.1. if we're using the Wagmi usePublicClient in this step? It looks like in the Viem Public Client isn't used for the Bundler Client in the gator-example.

Encode the delegation into a shareable URL:

```tsx
export function encodeDelegation(delegation: Delegation): string {
Copy link
Member

Choose a reason for hiding this comment

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

imports are missing for this step.

Comment on lines +272 to +280
const urlParams = new URLSearchParams(window.location.search);
const encodedDelegation = urlParams.get('delegation');

export function decodeDelegation(encodedDelegation: string): Delegation {
const decodedDelegationJson = Buffer.from(encodedDelegation, 'base64').toString('utf-8');
return JSON.parse(decodedDelegationJson) as Delegation;
}

const decodedDelegation = decodeDelegation(encodedDelegation);
Copy link
Member

Choose a reason for hiding this comment

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

same, imports are missing. specially for the dtk functions/ classes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there anything missing besides Delegation?

Copy link
Member

Choose a reason for hiding this comment

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

I think this covers!

Comment on lines +285 to +287
[Redeem the delegation](/delegation-toolkit/development/guides/delegation/execute-on-smart-accounts-behalf/#7-redeem-the-delegation) by submitting a user operation from the smart account created in [Step 3](#3-create-a-smart-account) to the `DelegationManager` contract.
The delegation manager validates the delegation and executes delegated actions.
In this case, the invitee can spend up to 0.001 ETH when using your dapp.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should change the words a bit, and say account be deployed for the first time users, or something? Invitee won't go through the step 3.


const delegations = [decodedDelegation];

const executions = createExecution({ target: zeroAddress });
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct, this will basically do a 0 value transfer to zeroAddress. You can check this file.
https://github.com/MetaMask/gator-examples/blob/c391305074d1d3faa61e65f3994828bb4f369022/examples/invitation-link-example/src/utils/delegationUtils.ts

Comment on lines +115 to +126
Create a [Viem Public Client](https://viem.sh/docs/clients/public) using Viem's `createPublicClient` function.
You will configure a Bundler Client with the Public Client, which you can use to query the signer's account state and interact with the blockchain network.

```tsx
import { createPublicClient, http } from 'viem';
import { sepolia as chain } from 'viem/chains';

const publicClient = createPublicClient({
chain,
transport: http(),
});
```
Copy link
Member

Choose a reason for hiding this comment

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

I think you also mentioned about getting this from Wagmi which was good point, this can be skipped and we can use wagmi hooks instead.

Copy link
Member

Choose a reason for hiding this comment

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

Added in the commit.

Copy link
Member

@AyushBherwani1998 AyushBherwani1998 left a comment

Choose a reason for hiding this comment

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

LGTM

@alexandratran alexandratran merged commit 1d16cff into feat/v0.13-dev Sep 15, 2025
5 checks passed
@alexandratran alexandratran deleted the 2209-referral-link-tutorial branch September 15, 2025 17:05
AyushBherwani1998 added a commit that referenced this pull request Sep 18, 2025
* Add delegation scopes guide 

* add delegation scopes guide

* minor edits and rename files

* add delegation scopes to manual sidebar

* restructure and edit

* edit to include scopes in guides

* address reviewer comments

---------

Co-authored-by: “AyushBherwani1998” <“ayush.bherwani1998@gmail.com”>
Co-authored-by: Alexandra Tran <alexandratran@protonmail.com>

* Update dtk tutorial for v0.13

* Update creating delegation references for v0.13

* Minor DTK fixes (#2277)

* Minor DTK fixes

* Apply suggestions from code review

Co-authored-by: Ayush Bherwani <ayush.bherwani1998@gmail.com>

---------

Co-authored-by: Ayush Bherwani <ayush.bherwani1998@gmail.com>

* Fix broken links (#2278)

* update execute on smart accounts behalf guide

* add parameters in delegation scopes

* update reference docs

* update guide: execute-on-smart-accounts-behalf

* Apply suggestions from code review

Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>

---------

Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>
Co-authored-by: AyushBherwani1998 <“ayush.bherwani1998@gmail.com”>

* Update caveats to use new declarative format

* update execution modes

* update parametes of caveats to new caveat configs

* update caveats api reference to new declarative format

* Apply suggestions from code review

Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>

* improve docs

---------

Co-authored-by: AyushBherwani1998 <“ayush.bherwani1998@gmail.com”>
Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>

* Adds guide: Check the delegation state 

* add check delegation state guide

* fix typos

* minor edits

---------

Co-authored-by: AyushBherwani1998 <“ayush.bherwani1998@gmail.com”>
Co-authored-by: Alexandra Tran <alexandratran@protonmail.com>

* Adds guide: Constrain a scope

* add constrain a scope documentation

* edit guide and fix links

* minor edits

---------

Co-authored-by: AyushBherwani1998 <“ayush.bherwani1998@gmail.com”>
Co-authored-by: Alexandra Tran <alexandratran@protonmail.com>

* Update reference section

* restructure reference docs

* add support for caveat enforcer client reference

* add delegation api index page, fix links, adjust toc style

* revert toc code font size

---------

Co-authored-by: AyushBherwani1998 <“ayush.bherwani1998@gmail.com”>
Co-authored-by: Alexandra Tran <alexandratran@protonmail.com>

* Update docs to use signer 

* update to use signer

* revert the ref changes

* apply reviewer suggestion

Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>

---------

Co-authored-by: AyushBherwani1998 <“ayush.bherwani1998@gmail.com”>
Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>

* Add DTK tutorial for creating an invite link (#2289)

* Fix typos

Co-authored-by: AyushBherwani1998 <“ayush.bherwani1998@gmail.com”>

* Update react-native.md (#2225)

useSDK is now modified and connect, terminate options have moved to sdk object inside useSDK function

Co-authored-by: Mohammad Shahbaz Alam <shahbaz17@users.noreply.github.com>

* Add DTK tutorial for creating an invite link

* Edit the Angular SDK content. (#2287)

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

* Fix deeplink urls (#2293)

* Edit the embedded wallets React builder component. (#2292)

* Edit the React builder component.

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

* Typo.

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

---------

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

* update tutorial

* Add DTK tutorial for creating an invite link

* Update react-native.md (#2225)

useSDK is now modified and connect, terminate options have moved to sdk object inside useSDK function

Co-authored-by: Mohammad Shahbaz Alam <shahbaz17@users.noreply.github.com>

* Edit the Angular SDK content. (#2287)

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

* Fix deeplink urls (#2293)

* update tutorial

* Edit the embedded wallets React builder component. (#2292)

* Edit the React builder component.

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

* Typo.

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

---------

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>

* add wagmi step and adjust headings

* address reviewer comments

* address reviewer comments

* minor edits

---------

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
Co-authored-by: Ayush Bherwani <ayush.bherwani1998@gmail.com>
Co-authored-by: AyushBherwani1998 <“ayush.bherwani1998@gmail.com”>
Co-authored-by: Arnav Chhabra <65032719+Halleys123@users.noreply.github.com>
Co-authored-by: Mohammad Shahbaz Alam <shahbaz17@users.noreply.github.com>
Co-authored-by: Byron Gravenorst <50852695+bgravenorst@users.noreply.github.com>

* revert the ew changes

* revert ew change

* v0.13 changes 

* v0.13 changes

* Apply suggestions from code review

Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>

---------

Co-authored-by: Ayush Bherwani <“ayush.bherwani1998@gmail.com”>
Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>

* minor edits

* remove todo

* use disallows instead of disables

* remove 7715 card from intro page

* improve delegation scope ref description

* add getMultiTokenPeriodEnforcerAvailableAmount action

---------

Signed-off-by: bgravenorst <byron.gravenorst@consensys.net>
Co-authored-by: “AyushBherwani1998” <“ayush.bherwani1998@gmail.com”>
Co-authored-by: Alexandra Tran <alexandratran@protonmail.com>
Co-authored-by: Alexandra Carrillo <12214231+alexandratran@users.noreply.github.com>
Co-authored-by: Arnav Chhabra <65032719+Halleys123@users.noreply.github.com>
Co-authored-by: Mohammad Shahbaz Alam <shahbaz17@users.noreply.github.com>
Co-authored-by: Byron Gravenorst <50852695+bgravenorst@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DTK tutorial for creating a referral link

4 participants