Skip to content

Migrating from 0.Y.Z to 1.Y.Z

If your app previously used Privy's Swift 0.Y.Z SDK, follow the migration guide below to upgrade to 1.Y.Z.

Initialization

Previously, apps initialized an instance of Privy via let privy = Privy(config: config).

Now, you should initialize Privy via an explicit initialize method from the SDK:

swift
let privy = Privy(config: config) 
let config = PrivyConfig(appId: "<your-app-id>") 
let privy: Privy = PrivySdk.initialize(config: config) 

This allows you to mock an instance of the Privy SDK in your application while unit testing.

TIP

Be sure to maintain a single instance of Privy across the lifetime of your application. Initializing multiple instances of Privy will result in unexpected errors.

Login with email and SMS

The OtpFlowState enum used in the login with SMS and login with email flows has been updated to have more descriptive intermediary and error states.

The new definition of the enum is:

swift
public enum OtpFlowState {
    case initial
    case sendingCode
    case awaitingCodeInput
    case submittingCode
    case done
    case error
    case sourceNotSpecified
    case sendCodeFailure(Error?) 
    case incorrectCode
    case loginError(Error) 
}

Login with custom auth

The custom auth interfaces that were previously accessible directly on the privy instance are now accessible via the privy.customJwt handle.

You should update your use of tokenProvider as follows:

swift
privy.tokenProvider = { return await fetchTokenFromServer() } 
privy.customJwt.setTokenProvider = { return await fetchTokenFromServer() } 

You should also update your use of loginWithCustomAccessToken as:

swift
privy.loginWithCustomAccessToken() 
privy.customJwt.loginWithCustomAccessToken() 

Embedded wallets

Previously, all embedded wallet APIs were accessible directly from the privy instance. These are now available under the privy.embeddedWallet handle.

For each method privy.<embedded-wallet-method-name>, you should now call it as privy.embeddedWallet.<embedded-wallet-method-name>.

As an example, instead of calling privy.connectWallet, you should now call privy.embeddedWallet.connectWallet:

swift
privy.connectWallet() 
privy.embeddedWallet.connectWallet() 

Please reference the embedded wallet documentation for full examples.

Getting an RPC provider

Previously, Privy exposed the RPC provider for embedded wallets as part of the connected state of the wallet.

Now, your app should get the RPC provider explicitly from the array of wallets stored in the connected state like so:

swift
// New implementation to retrieve provider
func rpcRequest() async throws {
    guard case .connected(let provider, let wallets) = myEmbeddedWalletState else { 
        print("Wallet not connected") 
    } 

    guard case .connected(let wallets) = privy.embeddedWallet.embeddedWalletState else { 
        print("Wallet not connected") 
        return
    } 

    guard let wallet = wallets.first else { 
        print("No wallets available") 
        return
    } 

    let provider = try privy.embeddedWallet.getProvider(for: wallet.address) 
}

This allows for better handling of HD wallets, where you can now get a distinct RPC provider instance for each HD wallet.