Skip to main content

Initializing Core Kit SFA Android SDK

Once you have installed the Web3Auth SDK, the next crucial step is to initialize it. This step requires passing various parameters that align with your project preferences. It's important to note that the initialization process is critical to the successful use of Web3Auth.

Create Web3Auth Instance

In your activity, create a SingleFactorAuth instance with singleFactorAuthArgs.

singleFactorAuth = SingleFactorAuth(singleFactorAuthArgs)

Arguments

singleFactorAuthArgs

The SingleFactorAuth Constructor takes singleFactorAuthArgs as input.

ParameterDescription
networkThe Web3auth network to be used by the SDK. Supported values are TorusNetwork.MAINNET, TorusNetwork.TESTNET, TorusNetwork.CYAN, TorusNetwork.AQUA

Instance

singleFactorAuthArgs = SingleFactorAuthArgs(TorusNetwork.TESTNET)
singleFactorAuth = SingleFactorAuth(singleFactorAuthArgs)

Example

class MainActivity : AppCompatActivity() {
// ...
private lateinit var singleFactorAuth: SingleFactorAuth
private lateinit var singleFactorAuthArgs: SingleFactorAuthArgs
private lateinit var loginParams: LoginParams
private var torusKey: TorusKey? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

singleFactorAuthArgs = SingleFactorAuthArgs(TorusNetwork.TESTNET)
singleFactorAuth = SingleFactorAuth(singleFactorAuthArgs)

// Setup UI and event handlers
val signInButton = findViewById<Button>(R.id.signIn)
signInButton.setOnClickListener { signIn() }
}

private fun signIn() {
loginParams = LoginParams("web3auth-firebase-examples", "sub_value", "id_token")
try {
torusKey = singleFactorAuth.getKey(loginParams).get()
} catch (e: ExecutionException) {
e.printStackTrace()
} catch (e: InterruptedException) {
e.printStackTrace()
}
println("""Private Key: ${torusKey!!.privateKey.toString(16)}""".trimIndent())
println("""Public Address: ${torusKey!!.publicAddress}""".trimIndent())
}
//...
}