Swift SDK

Getting Started

Getting started with zksync2-swift

This guide provides an overview of the most common operations developers need to start using Swift with ZKsync Era.

Ensure you have installed the zksync2-s SDK. If you still need to do so, please refer to the installation guide for detailed instructions.

Overview

While most of the existing SDKs should work out of the box, deploying smart contracts or using unique ZKsync features, like account abstraction, requires providing additional fields beyond those that Ethereum transactions have by default.

To begin, it is useful to have a basic understanding of the types of objects available and what they are responsible for, at a high level:

  • Client: Provides connection to the ZKsync Era blockchain, allowing querying of the blockchain state, such as account, block, or transaction details, querying event logs, or evaluating read-only code using call. Additionally, the client facilitates writing to the blockchain by sending transactions.
  • Signer: Wraps all operations that interact with an account. An account generally has a private key, which can be used to sign various types of payloads.
  • Wallet: A wrapper around Client and Signer that provides easy usage of the most common features.

Connecting to ZKsync

Once you have integrated zksync2-swift dependencies, connect to ZKsync using the endpoint of the operator node:

let ZKsync: ZKsync = ZKsyncImpl(URL(string: "https://sepolia.era.zksync.dev")!)

Connecting to Ethereum

Also, connect to Ethereum using the endpoint of the eth_sepolia node:

let ethereum: web3 = try! Web3.new(URL(string: "https://rpc.ankr.com/eth_sepolia")!)

let credentials = Credentials(privateKey: "<WALLET_PRIVATE_KEY>")
let keystoreManager = KeystoreManager([credentials])
ethereum.addKeystoreManager(keystoreManager)
For development and testing, it is recommended to use burner wallets. Avoid using real private keys to prevent security risks.

Made with ❤️ by the ZKsync Community