@@ -13,33 +13,47 @@ If used within the browser, wallets are not saved anywhere and disappear when th
13
13
If used within your application, wallets will disappear after the program is completed.
14
14
:::
15
15
16
- ## Create an account and add it to an empty ` Wallet `
16
+ ## Create a ` Wallet ` with a random account
17
17
18
- ``` ts title='Creating an Account and Adding it to an Empty Wallet'
19
- import { Web3 } from ' web3' ;
18
+ ``` ts title= Create Wallet with random account
19
+ import { Web3 } from " web3" ;
20
20
21
21
const web3 = new Web3 (/* PROVIDER */ );
22
22
23
- // 1st - creating a new empty wallet (0 accounts inside)
24
- const wallet = web3 .eth .accounts .wallet .create ();
25
-
26
- console .log (wallet );
23
+ /*
24
+ * creates wallet with 1 account
25
+ * @param: number of accounts you want to create within the wallet
26
+ */
27
+ const wallet = web3 .eth .accounts .wallet .create (1 );
27
28
/* ↳
28
- Wallet(0) [
29
+ Wallet(1) [
30
+ {
31
+ address: '0xE0A7859c5454B369Ab8089890A11efcB458eA13c',
32
+ privateKey: '0x0199829f0c95213670d48aa48abdb36c16c2ec3d11fe20e1fa8c0270ffb64110',
33
+ signTransaction: [Function: signTransaction],
34
+ sign: [Function: sign],
35
+ encrypt: [Function: encrypt]
36
+ },
29
37
_accountProvider: {
30
38
create: [Function: createWithContext],
31
39
privateKeyToAccount: [Function: privateKeyToAccountWithContext],
32
40
decrypt: [Function: decryptWithContext]
33
41
},
34
- _addressMap: Map(0 ) {},
42
+ _addressMap: Map(1 ) { '0xe0a7859c5454b369ab8089890a11efcb458ea13c' => 0 },
35
43
_defaultKeyName: 'web3js_wallet'
36
44
]
37
45
*/
46
+ ```
38
47
39
- // 2nd - create an account
40
- const account = web3 .eth .accounts .create ();
48
+ ## Create an account and add it to an empty ` Wallet `
49
+
50
+ ``` ts title='Creating an Account and add it to a Wallet'
51
+ import { Web3 } from " web3" ;
52
+
53
+ const web3 = new Web3 (/* PROVIDER */ );
41
54
42
- console .log (account )
55
+ // 1st - creating a new account
56
+ const account = web3 .eth .accounts .create ();
43
57
/* ↳
44
58
{
45
59
address: '0x0770B4713B62E0c08C43743bCFcfBAA39Fa703EF',
@@ -50,10 +64,8 @@ console.log(account)
50
64
}
51
65
*/
52
66
53
- // 3rd - add the account to the wallet
54
- web3 .eth .accounts .wallet .add (account );
55
-
56
- console .log (wallet );
67
+ // 2nd - add the account to the wallet
68
+ const wallet = web3 .eth .accounts .wallet .add (account );
57
69
/* ↳
58
70
Wallet(1) [
59
71
{
@@ -81,27 +93,9 @@ import { Web3 } from 'web3';
81
93
82
94
const web3 = new Web3 (/* PROVIDER */ );
83
95
84
- // 1st - creating a new empty wallet
85
- const wallet = web3 .eth .accounts .wallet .create ()
86
-
87
- console .log (wallet );
88
- /* ↳
89
- > Wallet(0) [
90
- _accountProvider: {
91
- create: [Function: createWithContext],
92
- privateKeyToAccount: [Function: privateKeyToAccountWithContext],
93
- decrypt: [Function: decryptWithContext]
94
- },
95
- _addressMap: Map(0) {},
96
- _defaultKeyName: 'web3js_wallet'
97
- ]
98
- */
99
-
100
- // 2nd - add an account to the wallet using a private key
96
+ // add an account to the wallet using a private key
101
97
const privateKey = ' 0x4651f9c219fc6401fe0b3f82129467c717012287ccb61950d2a8ede0687857ba'
102
- web3 .eth .accounts .wallet .add (privateKey );
103
-
104
- console .log (wallet );
98
+ const wallet = web3 .eth .accounts .wallet .add (privateKey );
105
99
/* ↳
106
100
Wallet(1) [
107
101
{
0 commit comments