For new React apps, we recommend the JavaScript SDK with React Hooks (@dynamic-labs-sdk/react-hooks) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the React quickstart (JavaScript SDK) to get started.
This guide is currently React only.
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.
Use the latest compatible versions of the Dynamic SDK and provider packages. Grab your environment ID from the Dynamic Dashboard under Developer > SDK & API Keys.
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.
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
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(), }); // ...}