Initializing SFA Swift SDK
After Installation, the next step to use Web3Auth is to create an instance, and initialize the SDK. Please note that these are the most critical steps where you need to pass on different parameters according to the preference of your project.
Parameters
The SingleFactoreAuth
constructor takes an object called Web3AuthOptions
as input. The
constructor parameters are listed below
Parameter | Description |
---|---|
clientId | Your Web3Auth Client Id from Web3Auth Dashboard. |
web3AuthNetwork | The Web3auth network to be used by the SDK. Supported values are .SAPPHIRE_MAINNET , .SAPPHIRE_DEVNET , .MAINNET , .TESTNET , .CYAN , and .AQUA |
sessionTime | Specifies the session duration in seconds. By default, the value is set to 86400 seconds (1 day), with a maximum session duration of up to 7 days. |
serverTimeOffset | Specifies the server time offset in seconds. This parameter is used to adjust the server time to the local time. The default value is 0 seconds. |
storageServerUrl? | Specifies the storage server URL. The default value is https://session.web3auth.io . |
Create instance
The initialize
method is responsible for authorizing the existing sessions, and initializing the
SDK. If the existing session is not valid, it'll throw an error.
import SingleFactorAuth
let options = Web3AuthOptions(
clientId: "YOUR_WEB3AUTH_CLIENT_ID",
web3AuthNetwork: .SAPPHIRE_MAINNET,
// Sets a session for 2 days, takes the input
// in seconds.
sessionTime: 172800
)
do {
let singleFactoreAuth = try SingleFactorAuth(params: options)
try await singleFactoreAuth.initialize()
} catch {
// Handle error
}