Introducing account abstraction for zkSync enabled chains. This guide will walk you through the setup of zkSync account abstraction with comprehensive method references and transaction examples.
Make sure to grab your Dynamic environment ID from the Dynamic Dashboard under Developer > SDK & API Keys, and replace it in the environmentId setting.
Returns a smart account client or session client based on the provided parameters. This method is the primary way to interact with zkSync smart accounts.
Copy
Ask AI
import { isZKsyncConnector } from '@dynamic-labs/ethereum-aa-zksync';// Get the smart account providerconst provider = wallet.connector.getAccountAbstractionProvider();// Get a session-based providerconst sessionProvider = wallet.connector.getAccountAbstractionProvider({ sessionId: 'your-session-id', origin: 'https://your-app.com'});
Create a session in order to make transactions on the users behalf
Copy
Ask AI
import { isZKsyncConnector } from '@dynamic-labs/ethereum-aa-zksync';const generateSessionConfig = () => { const currentTime = BigInt(Math.floor(Date.now() / 1000)); const oneDayPeriod = BigInt(86400); const defaultExpiryTime = (currentTime + oneDayPeriod).toString(); return { // expiration for the whole session. If not specified, defaults to 24hrs expiresAt: defaultExpiryTime, callPolicies: [], feeLimit: { limit: parseEther('1'), // maximum fees allowed to be covered during this session limitType: 2, // 0 = UNLIMITED, 1 = LIFETIME, 2 = ALLOWANCE period: defaultExpiryTime // time before the feeLimit resets }, transferPolicies: [ { maxValuePerUse: parseEther('10'), // maximum amount of ETH that can be sent in a single transaction target: '0x....', // to address for the transfer requests valueLimit: parseEther('10'), // maximum amount of ETH that can be sent during the period defined below limitType: 2, // 0 = UNLIMITED, 1 = LIFETIME, 2 = ALLOWANCE period: defaultExpiryTime // time before the valueLimit resets } ] }}const createSession = async () => { if (!primaryWallet?.connector || !isZKsyncConnector(primaryWallet.connector)) { throw new Error('ZKsync connector not found'); } const { sessionId, // session hash expiresAt, session: { sessionConfiguration, // session configuration w/ bigints as string sessionKey, // registered session private key sessionKeyValidator // session key validator contract address } } = await primaryWallet.connector.createSession({ sessionConfig: generateSessionConfig(), }); ...}