Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit a72e99a

Browse files
author
Santiago Trujillo Zuluaga
authored
optimize local wallet guides (#6773)
1 parent 7d7a9ea commit a72e99a

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

docs/docs/guides/wallet/local_wallet.md

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,47 @@ If used within the browser, wallets are not saved anywhere and disappear when th
1313
If used within your application, wallets will disappear after the program is completed.
1414
:::
1515

16-
## Create an account and add it to an empty `Wallet`
16+
## Create a `Wallet` with a random account
1717

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";
2020

2121
const web3 = new Web3(/* PROVIDER */);
2222

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);
2728
/*
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+
},
2937
_accountProvider: {
3038
create: [Function: createWithContext],
3139
privateKeyToAccount: [Function: privateKeyToAccountWithContext],
3240
decrypt: [Function: decryptWithContext]
3341
},
34-
_addressMap: Map(0) {},
42+
_addressMap: Map(1) { '0xe0a7859c5454b369ab8089890a11efcb458ea13c' => 0 },
3543
_defaultKeyName: 'web3js_wallet'
3644
]
3745
*/
46+
```
3847

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 */);
4154

42-
console.log(account)
55+
// 1st - creating a new account
56+
const account = web3.eth.accounts.create();
4357
/*
4458
{
4559
address: '0x0770B4713B62E0c08C43743bCFcfBAA39Fa703EF',
@@ -50,10 +64,8 @@ console.log(account)
5064
}
5165
*/
5266

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);
5769
/*
5870
Wallet(1) [
5971
{
@@ -81,27 +93,9 @@ import { Web3 } from 'web3';
8193

8294
const web3 = new Web3(/* PROVIDER */);
8395

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
10197
const privateKey = '0x4651f9c219fc6401fe0b3f82129467c717012287ccb61950d2a8ede0687857ba'
102-
web3.eth.accounts.wallet.add(privateKey);
103-
104-
console.log(wallet);
98+
const wallet = web3.eth.accounts.wallet.add(privateKey);
10599
/*
106100
Wallet(1) [
107101
{

0 commit comments

Comments
 (0)