fromMnemonic
Obtain the address and private key according to the provided mnemonic.
Usage
TronWeb.fromMnemonic(mnemonic, path, password, wordlist);
Parameters
Parameter | Description | Data Type |
---|---|---|
mnemonic | mnemonic. Separate each mnemonic with a space. | String |
path | BIP44 path, optional parameter. If you want to get an account other than index 0, you need to fill in this parameter, and the complete path is required. | String |
password | password of the mnemonic, optional | string |
wordlist | Language type, optional parameter. If the incoming mnemonic is not english(en), you need to fill in the corresponding language object through this parameter, see more in WordLists | Object |
Returns
Object - Returns the obtained account information, including mnemonic, public key, and private key. If the entered BIP44 path does not start with m/44'/195', throw an exception - Error: Invalid tron path provided.
Example
Example 1
> TronWeb.fromMnemonic( 'patch left empty genuine rain normal syrup yellow consider moon stock denial');
> {
"mnemonic": {
"phrase": "patch left empty genuine rain normal syrup yellow consider moon stock denial",
"password": "",
"wordlist": {
"locale": "en"
},
"entropy": "0xa0cfe524b0ab112c772ff82f51f3581d"
},
"privateKey": "0x0f9148e9be0c5b0213607a6491603891241ec7aa204918018dba691e4269ffe7",
"publicKey": "0x04642b796ba0acf06233e65695b977d28d2cae90fabd70dc0a300a831866b8f46ce5ee0ffa832492ce1b55a6c90463b2a31a03729b212281f6531558145b634ee0",
"address": "TPiD26cc1vptLxwYmw4waHTPCNgqtZ5SCX"
}
Example 2
> TronWeb.fromMnemonic( 'patch left empty genuine rain normal syrup yellow consider moon stock denial',"m/44'/195'/0'/0/1")
> {
"mnemonic": {
"phrase": "patch left empty genuine rain normal syrup yellow consider moon stock denial",
"password": "",
"wordlist": {
"locale": "en"
},
"entropy": "0xa0cfe524b0ab112c772ff82f51f3581d"
},
"privateKey": "0x5f3ecfca6e51dc70d58bca89d9b8fcb60cf193e0d8943af62311136c3e6504a0",
"publicKey": "0x04df45411faa27c933e10c83305da6f15138a018d2b539d8d4155a7e15f2552f9de3c6a7993e3814b4022a673faa70ad137bcc65857fc40cc0d59218ce28002361",
"address": "TXzMaz1QU4jKLctDu2QibrWvPtogtYHdW7"
}