ERC-7715 quickstart
This page demonstrates how to use ERC-7715 to request permissions from a wallet, and execute transactions on a user's behalf.
Prerequisites
Steps
1. Set up a Wallet Client
Set up a Viem Wallet Client using Viem's createWalletClient
function. This client will help you interact with MetaMask Flask.
Then, extend the Wallet Client functionality
using erc7715ProviderActions
. These actions enable you to request ERC-7715
permissions from the user.
import { createWalletClient, custom } from "viem";
import { erc7715ProviderActions } from "@metamask/delegation-toolkit/experimental";
const walletClient = createWalletClient({
transport: custom(window.ethereum),
}).extend(erc7715ProviderActions());
2. Set up a Public Client
Set up a Viem Public Client using Viem's createPublicClient
function.
This client will help you query the account state and interact with blockchain networks.
import { createPublicClient, http } from "viem";
import { sepolia as chain } from "viem/chains";
const publicClient = createPublicClient({
chain,
transport: http(),
});
3. 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 for executing transactions on behalf of the user.
This example uses MetaMask Smart Accounts as a session account.
import { privateKeyToAccount } from "viem/accounts";
import {
toMetaMaskSmartAccount,
Implementation
} from "@metamask/delegation-toolkit";
const privateKey = "0x...";
const account = privateKeyToAccount(privateKey);
const sessionAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [account.address, [], [], []],
deploySalt: "0x",
signatory: { account },
});