1- import type { BaseTransactionOptions } from "../../../transaction/types.js" ;
1+ import type { ThirdwebClient } from "../../../client/client.js" ;
2+ import type { Chain } from "../../../chains/types.js" ;
23import { randomBytesHex } from "../../../utils/random.js" ;
34import type { Account } from "../../../wallets/interfaces/wallet.js" ;
5+ import { getContract } from "../../../contract/contract.js" ;
46import {
57 createSessionWithSig ,
68 isCreateSessionWithSigSupported ,
@@ -15,10 +17,47 @@ import {
1517 UsageLimitRequest ,
1618} from "./types.js" ;
1719
20+ // MinimalAccount ABI - using the ABI definition from the JSON file
21+ const MinimalAccountAbi = [
22+ "error AllowanceExceeded(uint256 allowanceUsage, uint256 limit, uint64 period)" ,
23+ "error CallPolicyViolated(address target, bytes4 selector)" ,
24+ "error CallReverted()" ,
25+ "error ConditionFailed(bytes32 param, bytes32 refValue, uint8 condition)" ,
26+ "error InvalidDataLength(uint256 actualLength, uint256 expectedLength)" ,
27+ "error InvalidSignature(address msgSender, address thisAddress)" ,
28+ "error LifetimeUsageExceeded(uint256 lifetimeUsage, uint256 limit)" ,
29+ "error MaxValueExceeded(uint256 value, uint256 maxValuePerUse)" ,
30+ "error NoCallsToExecute()" ,
31+ "error SessionExpired()" ,
32+ "error SessionExpiresTooSoon()" ,
33+ "error SessionZeroSigner()" ,
34+ "error TransferPolicyViolated(address target)" ,
35+ "error UIDAlreadyProcessed()" ,
36+ "event Executed(address indexed to, uint256 value, bytes data)" ,
37+ "event SessionCreated(address indexed signer, (address signer, bool isWildcard, uint256 expiresAt, (address target, bytes4 selector, uint256 maxValuePerUse, (uint8 limitType, uint256 limit, uint256 period) valueLimit, (uint8 condition, uint64 index, bytes32 refValue, (uint8 limitType, uint256 limit, uint256 period) limit)[] constraints)[] callPolicies, (address target, uint256 maxValuePerUse, (uint8 limitType, uint256 limit, uint256 period) valueLimit)[] transferPolicies, bytes32 uid) sessionSpec)" ,
38+ "function createSessionWithSig((address signer, bool isWildcard, uint256 expiresAt, (address target, bytes4 selector, uint256 maxValuePerUse, (uint8 limitType, uint256 limit, uint256 period) valueLimit, (uint8 condition, uint64 index, bytes32 refValue, (uint8 limitType, uint256 limit, uint256 period) limit)[] constraints)[] callPolicies, (address target, uint256 maxValuePerUse, (uint8 limitType, uint256 limit, uint256 period) valueLimit)[] transferPolicies, bytes32 uid) sessionSpec, bytes signature)" ,
39+ "function eip712Domain() view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions)" ,
40+ "function execute((address target, uint256 value, bytes data)[] calls) payable" ,
41+ "function executeWithSig(((address target, uint256 value, bytes data)[] calls, bytes32 uid) wrappedCalls, bytes signature) payable" ,
42+ "function getCallPoliciesForSigner(address signer) view returns ((address target, bytes4 selector, uint256 maxValuePerUse, (uint8 limitType, uint256 limit, uint256 period) valueLimit, (uint8 condition, uint64 index, bytes32 refValue, (uint8 limitType, uint256 limit, uint256 period) limit)[] constraints)[])" ,
43+ "function getSessionExpirationForSigner(address signer) view returns (uint256)" ,
44+ "function getSessionStateForSigner(address signer) view returns (((uint256 remaining, address target, bytes4 selector, uint256 index)[] transferValue, (uint256 remaining, address target, bytes4 selector, uint256 index)[] callValue, (uint256 remaining, address target, bytes4 selector, uint256 index)[] callParams))" ,
45+ "function getTransferPoliciesForSigner(address signer) view returns ((address target, uint256 maxValuePerUse, (uint8 limitType, uint256 limit, uint256 period) valueLimit)[])" ,
46+ "function isWildcardSigner(address signer) view returns (bool)" ,
47+ ] as const ;
48+
1849/**
1950 * @extension ERC7702
2051 */
2152export type CreateSessionKeyOptions = {
53+ /**
54+ * The Thirdweb client
55+ */
56+ client : ThirdwebClient ;
57+ /**
58+ * The chain to create the session key on
59+ */
60+ chain : Chain ;
2261 /**
2362 * The admin account that will perform the operation.
2463 */
@@ -48,16 +87,16 @@ export type CreateSessionKeyOptions = {
4887/**
4988 * Creates session key permissions for a specified address.
5089 * @param options - The options for the createSessionKey function.
51- * @param {Contract } options.contract - The EIP-7702 smart EOA contract to create the session key from
5290 * @returns The transaction object to be sent.
5391 * @example
5492 * ```ts
5593 * import { createSessionKey } from 'thirdweb/wallets/in-app';
5694 * import { sendTransaction } from 'thirdweb';
5795 *
5896 * const transaction = createSessionKey({
97+ * client,
98+ * chain,
5999 * account: account,
60- * contract: accountContract,
61100 * sessionKeyAddress: TEST_ACCOUNT_A.address,
62101 * durationInSeconds: 86400, // 1 day
63102 * grantFullPermissions: true
@@ -67,11 +106,10 @@ export type CreateSessionKeyOptions = {
67106 * ```
68107 * @extension ERC7702
69108 */
70- export function createSessionKey (
71- options : BaseTransactionOptions < CreateSessionKeyOptions > ,
72- ) {
109+ export function createSessionKey ( options : CreateSessionKeyOptions ) {
73110 const {
74- contract,
111+ client,
112+ chain,
75113 account,
76114 sessionKeyAddress,
77115 durationInSeconds,
@@ -84,6 +122,14 @@ export function createSessionKey(
84122 throw new Error ( "durationInSeconds must be positive" ) ;
85123 }
86124
125+ // Create contract from account.address with MinimalAccount ABI
126+ const contract = getContract ( {
127+ address : account . address ,
128+ chain,
129+ client,
130+ abi : MinimalAccountAbi ,
131+ } ) ;
132+
87133 return createSessionWithSig ( {
88134 async asyncParams ( ) {
89135 const req = {
0 commit comments