grantPermissions
1 function grantPermissions<TAccount>( 2 client, 3 signer, 4 params, 5 ): 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.
Example
1 // Create a session key and grant root permissions 2 const sessionKey = LocalAccountSigner.generatePrivateKeySigner(); 3 const account = await client.requestAccount(); 4 5 const permissions = await client.grantPermissions({ 6 account: account.address, 7 expirySec: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour from now 8 key: { 9 publicKey: await sessionKey.getAddress(), 10 type: "secp256k1", 11 }, 12 permissions: [{ type: "root" }], 13 }); 14 15 // Use the permissions to prepare a call 16 const preparedCalls = await client.prepareCalls({ 17 calls: [{ to: zeroAddress, value: "0x0" }], 18 from: account.address, 19 capabilities: { 20 paymasterService: { 21 policyId: "your-paymaster-policy-id", 22 }, 23 permissions, 24 }, 25 }); 26 27 // Sign with the session key 28 const signedCalls = await signPreparedCalls(sessionKey, preparedCalls); 29 30 // Send the prepared call using the session key 31 const result = await client.sendPreparedCalls({ 32 ...signedCalls, 33 capabilities: { 34 permissions, 35 }, 36 });
Type Parameters
| Type Parameter | Default type |
|---|---|
|
|
Parameters
| 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 |
Returns
Promise<GrantPermissionsResult>
A Promise that resolves to the result containing a context identifier