Wallet Creation
Wallet creation is a two stage process. First, a mnemonic seed phrase is generated. Once you have a seed phrase, this can then be used in tandem with a password to generate a new wallet.
Android
Anything related to Wallet Management on Android is handled by the WalletManagement
class that can be accessed via the walletManagement
method on your ZumoKit
instance.
The first step in creating a wallet is the generation of a mnemonic seed phrase. This is handled by the generateMnemonic
method on the WalletManagement
class. A single parameter can be provided which defines the number of words that should be generated.
In the below example, you can see that 12
is the parameter provided to the generateMnemonic
method. This is a sensible default but if security is paramount, this can be increased.
import com.zumo.zumokit.ZumoKit;
import com.zumo.zumokit.WalletManagement;
WalletManagement wm = this.zumoKit.walletManagement();
String mnemonic = wm.generateMnemonic(12);
Once a seed phrase has been generated, this can then be used to create a new wallet or "keystore". To do this, provide the currency (ETH or BTC), password and mnemonic to the createWallet
method on the WalletManagement
class.
import com.zumo.zumokit.ZumoKit;
import com.zumo.zumokit.WalletManagement;
import com.zumo.zumokit.Keystore;
import com.zumo.zumokit.Currency;
Keystore keystore = wm.createWallet(Currency.ETH, "password123", mnemonic);
boolean unlockedStatus = wm.unlockWallet(keystore, "password123");
In the above example we also unlock the wallet immediately using the unlockWallet
method so that the user can begin to use it straight away.
iOS
Wallet Management on iOS is handled by the CPWalletManagement
class. An instance of this class can be obtained from the walletManagement
property on your ZumoKitImpl
instance.
The first step in creating a wallet is the generation of a mnemonic seed phrase. This is handled by the generateMnemonic
method on the CPWalletManagement
class. A single parameter can be provided which defines the number of words that should be generated.
In the below example, you can see that 12
is the parameter provided to the generateMnemonic
method. This is a sensible default but if security is paramount, this can be increased.
#import <ZumoKitSDK/ZumoKit.h>
#import <ZumoKitSDK/CPWalletManagement.h>
CPWalletManagement *walletManagement = [_zumoKit walletManagement];
NSString *mnemonicPhrase = [walletManagement generateMnemonic:12];
Once a seed phrase has been generated, this can then be used to create a new wallet or "keystore". To do this, provide the currency (ETH or BTC), password and mnemonic to the createWallet
method on the CPWalletManagement
class.
#import <ZumoKitSDK/ZumoKit.h>
#import <ZumoKitSDK/CPWalletManagement.h>
#import <ZumoKitSDK/CPKeystore.h>
#import <ZumoKitSDK/CPCurrency.h>
CPKeystore *keystore = [walletManagement
createWallet:CPCurrencyETH
password:@"password123"
mnemonic:mnemonicPhrase];
BOOL status = [walletManagement
unlockWallet:keystore
password:@"password123"];
React Native
Unlike the native counterparts, the React Native implementation of ZumoKit condenses the wallet creation process down into a single step. Wallet creation is done via the createWallet
method on the ZumoKit
singleton, which accepts a password
and mnemonicCount
that defines the number of words to use in the seed phrase.
import ZumoKit from 'react-native-zumo-kit';
try {
const wallet = async ZumoKit.createWallet("password123", 12);
} catch(error) {
// Handle error creating wallet here.
}
Wallets are returned unlocked and the promise is rejected (causing an error to be thrown) if there is a problem creating the wallet.