@@ -12,7 +12,7 @@ A couple examples to help you get started.
1212
1313``` typescript
1414import {
15- LumWallet ,
15+ LumWalletFactory ,
1616 LumClient ,
1717 LumTypes ,
1818 LumUtils ,
@@ -21,15 +21,15 @@ import {
2121} from ' @lum-network/sdk-javascript'
2222```
2323
24- ### Create a wallet
24+ ### Software wallets
2525
2626#### Mnemonic
2727``` typescript
2828// Create a new cryptographically secure random mnemonic
2929const mnemonic = LumUtils .generateMnemonic (12 );
3030
3131// Create a wallet instance based on this fresh mnemonic
32- const wallet = await LumWallet .fromMnemonic (mnemonic );
32+ const wallet = await LumWalletFactory .fromMnemonic (mnemonic );
3333```
3434
3535#### Private key
@@ -38,12 +38,12 @@ const wallet = await LumWallet.fromMnemonic(mnemonic);
3838const privateKey = LumUtils .generatePrivateKey ();
3939
4040// Create a wallet instance based on this fresh private key
41- const wallet = await LumWallet .fromPrivateKey (mnemonic );
41+ const wallet = await LumWalletFactory .fromPrivateKey (mnemonic );
4242console .log (` Wallet address: ${wallet .address } ` );
4343
4444// Create a wallet instance based on an hexadecimal private key (ex: user input - 0x is optional)
4545const hexPrivateKey = ' 0xb8e62c34928025cdd3aef6cbebc68694b5ad9209b2aff6d3891c8e61d22d3a3b' ;
46- const existingWallet = await LumWallet .fromPrivateKey (LumUtils .keyFromHex (hexPrivateKey ));
46+ const existingWallet = await LumWalletFactory .fromPrivateKey (LumUtils .keyFromHex (hexPrivateKey ));
4747console .log (` Existing wallet address: ${wallet .address } ` );
4848```
4949
@@ -53,10 +53,49 @@ console.log(`Existing wallet address: ${wallet.address}`);
5353const privateKey = LumUtils .generatePrivateKey ();
5454// Create a keystore (or consume user input)
5555const keystore = LumUtils .generateKeyStore (privateKey , ' some-password' );
56- const wallet = await LumWallet .fromKeyStore (keystore , ' some-password' );
56+ const wallet = await LumWalletFactory .fromKeyStore (keystore , ' some-password' );
5757console .log (` Wallet address: ${wallet .address } ` );
5858```
5959
60+ ### Hardware wallets
61+
62+ ** IMPORTANT NOTES:**
63+ - Transaction signature using Hardware devices is currently work in progress, therefore broadcasting a transaction is not possible at the moment.
64+ - Derivation path using the Cosmos Ledger application cannot be set to the default Lum Path for now ` m/44'/118'/0'/*/* ` and must remain on the Cosmos path ` m/44'/'837/0'/*/* `
65+
66+ #### Ledger
67+
68+ The SDK only provides access to the Ledger API using a provided Transport.
69+ Ledger transport must be initialized and handled by the code using the SDK.
70+
71+ See [ LedgerHQ/ledgerjs documentation] ( https://github.com/LedgerHQ/ledgerjs ) for more information.
72+
73+ ``` typescript
74+ import TransportNodeHid from ' @ledgerhq/hw-transport-node-hid' ;
75+
76+ // Connect your ledger device
77+ // Unlock it
78+ // Open the Cosmos application
79+
80+ // Create a Node HID transport
81+ const transport = await TransportNodeHid .create ();
82+
83+ // Create the ledger based wallet instance
84+ const wallet = await LumWalletFactory .fromLedgerTransport (transport , ` m/44'/118'/0'/0/0 ` , ' lum' );
85+
86+ // Change account to 1 and wallet to 1 (optional)
87+ await wallet .useAccount (` m/44'/118'/0'/1/1 ` , ' lum' );
88+
89+ // Get account information
90+ const account = await testnetClient .getAccount (wallet .getAddress ());
91+ if (account === null ) {
92+ console .log (' Account: not found' );
93+ } else {
94+ console .log (` Account: ${account .address }, ${account .accountNumber }, ${account .sequence } ` );
95+ }
96+ ```
97+
98+
6099### Connect to the testnet
61100
62101``` typescript
@@ -78,7 +117,7 @@ if (account === null) {
78117
79118#### Get account balances
80119``` typescript
81- const balances = await testnetClient .getBalancesUnverified (wallet .address );
120+ const balances = await testnetClient .getAllBalancesUnverified (wallet .address );
82121if (balances .length === 0 ) {
83122 console .log (' Balances: empty account' );
84123} else {
@@ -115,8 +154,19 @@ const fee = {
115154 amount: [{ denom: LumConstants .LumDenom , amount: ' 1' }],
116155 gas: ' 100000' ,
117156};
157+ // Fetch account number and sequence
158+ const account = await testnetClient .getAccount (wallet .address );
159+ // Create the transaction document
160+ const doc = {
161+ accountNumber: account .accountNumber ,
162+ chainId ,
163+ fee: fee ,
164+ memo: ' my transaction memo' ,
165+ messages: [sendMsg ],
166+ sequence: account .sequence ,
167+ };
118168// Sign and broadcast the transaction using the client
119- const broadcastResult = await clt .signAndBroadcastTx (w1 , [ sendMsg ], fee , ' hello memo! ' );
169+ const broadcastResult = await clt .signAndBroadcastTx (w1 , doc );
120170// Verify the transaction was succesfully broadcasted and made it into a block
121171console .log (` Broadcast success: ${LumUtils .broadcastTxCommitSuccess (broadcastResult )} ` );
122172```
0 commit comments