Skip to main content

Wallet Client API reference

The following API methods are related to the Viem Wallet Client.

grantPermissions

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

info

To use grantPermissions, 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.
permissionPermissionYesThe permission to grant to the user.
signerSignerYesThe account to which the permission will be assigned.
isAdjustmentAllowedbooleanNoWhether the user is allowed to modify the requested permission. The default is true.

Example

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

const expiry = Math.floor(Date.now() / 1000 + 604_800); // 1 week from now.
const currentTime = Math.floor(Date.now() / 1000); // now

// Address of the wallet that will manage the session. It can
// be either a smart account or an externally owned account (EOA)
const sessionAccount = "0x1431..";

const grantedPermissions = await walletClient.grantPermissions([{
chainId: chain.id,
expiry,
signer: {
type: "account",
data: {
address: sessionAccount,
},
},
permission: {
type: "native-token-stream",
data: {
initialAmount: 1n, // 1 wei
amountPerSecond: 1n, // 1 wei per second
maxAmount: 10n, // 10 wei
startTime: currentTime,
justification: "Payment for a week long subscription",
},
},
}]);

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
delegationManager0x${string}YesThe address of the Delegation Manager.
permissionsContext0x${string}YesEncoded calldata for redeeming delegations. If you're not using ERC-7715, you can use the redeemDelegation utility function to generate the calldata manually.

Example

import { walletClient, publicClient } from "./config.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.factory,
data: accountMetadata.factoryData,
});

// You should wait for 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
});