function grantPermissions<TAccount>(
client,
signer,
params,
): Promise<GrantPermissionsResult>;Defined in: account-kit/wallet-client/src/client/actions/grantPermissions.ts:95
Grants permissions to a smart account by creating a session. This allows another key to perform operations on behalf of the account.
// Create a session key and grant root permissions
const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
const account = await client.requestAccount();
const permissions = await client.grantPermissions({
account: account.address,
expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now
key: {
publicKey: await sessionKey.getAddress(),
type: "secp256k1",
},
permissions: [{ type: "root" }],
});
// Use the permissions to prepare a call
const preparedCalls = await client.prepareCalls({
calls: [{ to: zeroAddress, value: "0x0" }],
from: account.address,
capabilities: {
paymasterService: {
policyId: "your-paymaster-policy-id",
},
permissions,
},
});
// Sign with the session key
const signedCalls = await signPreparedCalls(sessionKey, preparedCalls);
// Send the prepared call using the session key
const result = await client.sendPreparedCalls({
...signedCalls,
capabilities: {
permissions,
},
});| Type Parameter | Default type |
|---|---|
|
|
| Parameter | Type | Description |
|---|---|---|
|
| The wallet API client to use for the request |
|
| The signer of the smart account |
| { [K in string | number | symbol]: (Omit<{ chainId: `0x${string}`; expirySec?: number; key: { publicKey: `0x${string}`; type: "secp256k1" | "ecdsa" | "contract" }; permissions: ({ data: { allowance: `0x${(...)}` }; type: "native-token-transfer" } | { data: { address: `0x${(...)}`; allowance: `0x${(...)}` }; type: "erc20-token-transfer" } | { data: { limit: `0x${(...)}` }; type: "gas-limit" } | { data: { address: `0x${(...)}` }; type: "contract-access" } | { data: { functions: (...)[] }; type: "account-functions" } | { data: { functions: (...)[] }; type: "functions-on-all-contracts" } | { data: { address: `0x${(...)}`; functions: (...)[] }; type: "functions-on-contract" } | { data?: undefined; type: "root" })[] } & { account: `0x${string}` }, "account" | "chainId"> & (IsUndefined<TAccount> extends true ? { account: `0x${string}` } : { account?: undefined }))[K] } | The parameters for granting permissions |
Promise<GrantPermissionsResult>
A Promise that resolves to the result containing a context identifier