Skip to main content

Wallet Client actions reference

The following actions are related to the Viem Wallet Client used to execute on a MetaMask user's behalf.

requestExecutionPermissions

Requests permissions from the MetaMask extension account according to the ERC-7715 specifications.

info

To use requestExecutionPermissions, the Viem Wallet Client must be extended with erc7715ProviderActions.

Parameters

NameTypeRequiredDescription
chainIdnumberYesThe chain ID on which the permission is being requested.
addressAddressNoAddress of the wallet to which the permission is being requested.
expirynumberYesThe timestamp (in seconds) by which the permission must expire.
permissionSupportedPermissionParamsYesThe permission to be requested. The toolkit supports multiple ERC-7715 permissions.
signerSignerParamYesThe account to which the permission will be assigned.
isAdjustmentAllowedbooleanYesDefines whether the user is allowed to modify the requested permission.

Example

import { sepolia as chain } from "viem/chains";
import { parseUnits } from "viem";
import { walletClient } from "./client.ts";

const currentTime = Math.floor(Date.now() / 1000);
const expiry = currentTime + 604800;

const grantedPermissions = await walletClient.requestExecutionPermissions([{
chainId: chain.id,
expiry,
signer: {
type: "account",
data: {
address: "0x0955fFD7b83e5493a8c1FD5dC87e2CF37Eacc44a",
},
},
permission: {
type: "erc20-token-periodic",
data: {
tokenAddress: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
periodAmount: parseUnits("10", 6),
periodDuration: 86400,
justification?: "Permission to transfer 1 USDC every day",
},
},
isAdjustmentAllowed: true,
}]);

sendTransactionWithDelegation

Sends a transaction to redeem delegated permissions according to the ERC-7710 specifications.

info

To use sendTransactionWithDelegation, the Viem Wallet Client must be extended with erc7710WalletActions.

Parameters

See the Viem sendTransaction parameters. This function has the same parameters, and it also requires the following parameters:

NameTypeRequiredDescription
delegationManagerAddressYesThe address of the Delegation Manager.
permissionsContextHexYesEncoded calldata for redeeming delegations. If you're not using ERC-7715, you can use the redeemDelegations utility function to generate the calldata manually.

Example

import { walletClient, publicClient } from "./client.ts";

// These properties must be extracted from the permission response. See
// `grantPermissions` action to learn how to request permissions.
const permissionsContext = permissionsResponse[0].context;
const delegationManager = permissionsResponse[0].signerMeta.delegationManager;
const accountMetadata = permissionsResponse[0].accountMeta;

if (accountMetadata?.length !== 0) {
// If the granted permission contains accountMetadata, this must be executed before attempting to
// redeem the delegation.

// This transaction will deploy the delegator account.
const hash = walletClient.sendTransaction({
to: accountMetadata[0].factory,
data: accountMetadata[0].factoryData,
});

// You should wait for the transaction to be successfully executed.
// You can use the TransactionReceipt.status to verify the state.
await publicClient.waitForTransactionReceipt( { hash });
}

const hash = walletClient.sendTransactionWithDelegation({
chain,
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
value: 1n,
permissionsContext,
delegationManager
});