Android example demonstrating Solana blockchain integration with MetaMask Embedded Wallets (formerly Web3Auth Plug and Play). Built with Jetpack Compose, Koin, and sol4k.
- Social login via Google (using grouped connection)
- Solana wallet creation via Ed25519 private key derivation
- Get Solana wallet address (public key) and devnet SOL balance
- Send SOL transactions on Solana Devnet
- Session persistence across app restarts
- MVVM architecture with Jetpack Compose UI
- Android Studio Hedgehog (2023.1.1) or later
- Android API 26+, Compile SDK 34
- JDK 17+
- MetaMask Embedded Wallets Dashboard account
git clone https://github.com/Web3Auth/web3auth-android-examples.git
cd web3auth-android-examples/android-solana-example- Create a project on the Embedded Wallets Dashboard.
- Set up a Google connection and note your Auth Connection ID and Grouped Auth Connection ID.
- Allowlist your redirect URI:
com.example.androidsolanaexample://auth
object Web3AuthSampleConfig {
const val CLIENT_ID = "YOUR_WEB3AUTH_CLIENT_ID"
const val REDIRECT_URL = "com.example.androidsolanaexample://auth"
const val GOOGLE_AUTH_CONNECTION_ID = "YOUR_GOOGLE_AUTH_CONNECTION_ID"
const val GOOGLE_CLIENT_ID = "YOUR_GOOGLE_CLIENT_ID"
const val GROUPED_AUTH_CONNECTION_ID = "YOUR_GROUPED_AUTH_CONNECTION_ID"
}dependencies {
implementation("com.github.web3auth:web3auth-android-sdk:10.0.1")
implementation("org.sol4k:sol4k:0.4.1")
implementation("io.insert-koin:koin-android:3.5.3")
}The SDK is initialized in the Koin module and the activity calls initialize() via the ViewModel:
// Login
val loginParams = LoginParams(
authConnection = AuthConnection.GOOGLE,
authConnectionId = Web3AuthSampleConfig.GOOGLE_AUTH_CONNECTION_ID,
groupedAuthConnectionId = Web3AuthSampleConfig.GROUPED_AUTH_CONNECTION_ID
)
web3Auth.connectTo(loginParams).await()After login, use getEd25519PrivateKey() to get the Solana private key:
val ed25519PrivateKey = web3Auth.getEd25519PrivateKey()
val solanaKeyPair = Keypair.fromSecretKey(ed25519PrivateKey.hexToByteArray())
val publicKey = solanaKeyPair.publicKey.toBase58()val connection = Connection(RpcUrl.DEVNET)
val balance = connection.getBalance(solanaKeyPair.publicKey)override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
web3Auth.setResultUrl(intent?.data)
}
override fun onResume() {
super.onResume()
if (Web3Auth.getCustomTabsClosed()) {
web3Auth.setResultUrl(null)
Web3Auth.setCustomTabsClosed(false)
}
}- Android SDK Documentation
- sol4k Documentation
- MetaMask Embedded Wallets Docs
- Dashboard
- Builder Hub Community
MIT — see LICENSE for details.