Getting Started

Learn how to integrate ZKsync SSO into your app.

Integrating ZKsync SSO into your app requires minimal amount of changes.

ZKsync SSO can be used standalone or added as one of the options in the onboarding library of your choice.

Quick Start

Just 2 steps:

  1. Install the ZKsync SSO SDK package.
    npm i zksync-sso
    
  2. Add ZKsync SSO connector to your app.
    import { zksyncSsoConnector, callPolicy } from "zksync-sso/connector";
    import { zksyncSepoliaTestnet } from "viem/chains";
    import { createConfig, connect } from "@wagmi/core";
    import { erc20Abi } from "viem";
    
    const ssoConnector = zksyncSsoConnector({
      // Optional session configuration, if omitted user will have to sign every transaction via Auth Server
      session: {
        expiry: "1 day",
    
        // Allow up to 0.1 ETH to be spend in gas fees
        feeLimit: parseEther("0.1"),
    
        transfers: [
          // Allow ETH transfers of up to 0.1 ETH to specific address
          {
            to: "0x188bd99cd7D4d78d4E605Aeea12C17B32CC3135A",
            valueLimit: parseEther("0.1"),
          },
        ],
    
        // Allow calling specific smart contracts (e.g. ERC20 transfer):
        contractCalls: [
          callPolicy({
            address: "0xa1cf087DB965Ab02Fb3CFaCe1f5c63935815f044",
            abi: erc20Abi,
            functionName: "transfer",
            constraints: [
              // Only allow transfers to this address. Or any address if omitted
              {
                index: 0, // First argument of erc20 transfer function, recipient address
                value: "0x6cC8cf7f6b488C58AA909B77E6e65c631c204784",
              },
    
              // Allow transfering up to 0.2 tokens per hour
              // until the session expires
              {
                index: 1,
                limit: {
                  limit: parseUnits("0.2", TOKEN.decimals),
                  period: "1 hour",
                },
              },
            ],
          }),
        ],
      },
    });
    
    const wagmiConfig = createConfig({
      connectors: [ssoConnector],
      ..., // your wagmi config https://wagmi.sh/core/api/createConfig
    });
    
    const connectWithSSO = () => {
      connect(wagmiConfig, {
        connector: ssoConnector,
        chainId: zksyncSepoliaTestnet.id, // or another chain id that has SSO support
      });
    };
    

Interfaces

You can find the full list of options and their descriptions in the Interfaces section.

Examples

We provide several example apps to help you get started quickly. Find them on our GitHub repository.


Made with ❤️ by the ZKsync Community