Integrate Embedded Wallets with the Nibiru Blockchain in Android
While using the Web3Auth Android SDK, you get the private key within the user scope after successful authorization. This private key can be used to retrieve the user's address, and interact with Nibiru to make any blockchain calls. We have highlighted a few here for getting you started quickly on that.
Chain details for Nibiru
- Mainnet
- Chain ID: 0x1AF4
- Public RPC URL:
https://evm-rpc.nibiru.fi - Display Name: Nibiru Mainnet
- Block Explorer Link:
https://nibiscan.io - Ticker: NIBI
- Ticker Name: Nibiru
Prerequisites
This doc assumes you have already setup your project in the Embedded Wallets dashboard (formerly Web3Auth), and have integrated Embedded Wallets in your Android app. If you haven't done that yet, you can learn how to integrate Embedded Wallets in your Android app.
Installation
To interact with Ethereum in Android, you can use any EIP1193-compatible package available for Android. Here we're using web3j to demonstrate how to make blockchain calls using it with Embedded Wallets.
dependencies {
// ...
implementation 'org.web3j:core:4.8.7-android'
}
Initialize
We'll initialize the Web3j instance with the RPC URL of the network you want to connect to. This client allows us to interact with the blockchain. To get the public RPC URL, see ChainList.
import org.web3j.protocol.Web3j
import org.web3j.protocol.http.HttpService
// Please avoid using public RPC URL in production, use services
// like Infura.
val web3 = Web3j.build(HttpService("YOUR_RPC_URL"))
Get account
Once user has successfully logged in, you can retrieve the user's private key using the getPrivKey method from the Embedded Wallets Android SDK. We'll use this private key to generate the Credentials for the user.
This Credentials object has the user's keypair of private key and public key, and can be used to sign the transactions. Please note, that this assumes that the user has already logged in and the private key is available.
import org.web3j.crypto.Credentials
// Use your Embedded Wallets SDK instance to get the private key
val privateKey = web3Auth.getPrivKey()
// Generate the Credentials
val credentials = Credentials.create(privateKey)
// Get the address
val address = credentials.address