importAccount method
Future<Map>
importAccount({
- required EVMKeyType keyType,
- required String key,
- required String name,
- required String password,
- String derivePath = default_derive_path,
Import keyPair from mnemonic, privateKey or keystore. keyType: string, key: string, derivePath: string, password: string
Implementation
Future<Map> importAccount({
required EVMKeyType keyType,
required String key,
required String name,
required String password,
String derivePath = default_derive_path,
}) async {
// generate json from js-api
final String type = keyType.toString().split('.')[1];
if (type == "keystore") {
key = key.replaceAll("\"", "\\\"");
}
String code =
'eth.keyring.recover("$type", "$key", "$derivePath", "$password")';
code = code.replaceAll(RegExp(r'\t|\n|\r'), '');
final Map acc = _formatAccountData(
(await serviceRoot.webView!.evalJavascript(code)) ?? {});
return {...acc, type: key, 'name': name};
}