Skip to content

Commit

Permalink
optimize local wallet guides (#6773)
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Trujillo Zuluaga authored Jan 29, 2024
1 parent 7d7a9ea commit a72e99a
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions docs/docs/guides/wallet/local_wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,47 @@ If used within the browser, wallets are not saved anywhere and disappear when th
If used within your application, wallets will disappear after the program is completed.
:::

## Create an account and add it to an empty `Wallet`
## Create a `Wallet` with a random account

```ts title='Creating an Account and Adding it to an Empty Wallet'
import { Web3 } from 'web3';
```ts title= Create Wallet with random account
import { Web3 } from "web3";

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

// 1st - creating a new empty wallet (0 accounts inside)
const wallet = web3.eth.accounts.wallet.create();

console.log(wallet);
/*
* creates wallet with 1 account
* @param: number of accounts you want to create within the wallet
*/
const wallet = web3.eth.accounts.wallet.create(1);
/*
Wallet(0) [
Wallet(1) [
{
address: '0xE0A7859c5454B369Ab8089890A11efcB458eA13c',
privateKey: '0x0199829f0c95213670d48aa48abdb36c16c2ec3d11fe20e1fa8c0270ffb64110',
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt]
},
_accountProvider: {
create: [Function: createWithContext],
privateKeyToAccount: [Function: privateKeyToAccountWithContext],
decrypt: [Function: decryptWithContext]
},
_addressMap: Map(0) {},
_addressMap: Map(1) { '0xe0a7859c5454b369ab8089890a11efcb458ea13c' => 0 },
_defaultKeyName: 'web3js_wallet'
]
*/
```

// 2nd - create an account
const account = web3.eth.accounts.create();
## Create an account and add it to an empty `Wallet`

```ts title='Creating an Account and add it to a Wallet'
import { Web3 } from "web3";

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

console.log(account)
// 1st - creating a new account
const account = web3.eth.accounts.create();
/*
{
address: '0x0770B4713B62E0c08C43743bCFcfBAA39Fa703EF',
Expand All @@ -50,10 +64,8 @@ console.log(account)
}
*/

// 3rd - add the account to the wallet
web3.eth.accounts.wallet.add(account);

console.log(wallet);
// 2nd - add the account to the wallet
const wallet = web3.eth.accounts.wallet.add(account);
/*
Wallet(1) [
{
Expand Down Expand Up @@ -81,27 +93,9 @@ import { Web3 } from 'web3';

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

// 1st - creating a new empty wallet
const wallet = web3.eth.accounts.wallet.create()

console.log(wallet);
/*
> Wallet(0) [
_accountProvider: {
create: [Function: createWithContext],
privateKeyToAccount: [Function: privateKeyToAccountWithContext],
decrypt: [Function: decryptWithContext]
},
_addressMap: Map(0) {},
_defaultKeyName: 'web3js_wallet'
]
*/

// 2nd - add an account to the wallet using a private key
// add an account to the wallet using a private key
const privateKey = '0x4651f9c219fc6401fe0b3f82129467c717012287ccb61950d2a8ede0687857ba'
web3.eth.accounts.wallet.add(privateKey);

console.log(wallet);
const wallet = web3.eth.accounts.wallet.add(privateKey);
/*
Wallet(1) [
{
Expand Down

1 comment on commit a72e99a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: a72e99a Previous: 6c075db Ratio
processingTx 9186 ops/sec (±3.88%) 9301 ops/sec (±4.81%) 1.01
processingContractDeploy 40742 ops/sec (±7.41%) 39129 ops/sec (±7.62%) 0.96
processingContractMethodSend 19289 ops/sec (±4.75%) 19443 ops/sec (±5.19%) 1.01
processingContractMethodCall 39780 ops/sec (±6.47%) 38971 ops/sec (±6.34%) 0.98
abiEncode 45246 ops/sec (±6.88%) 44252 ops/sec (±6.92%) 0.98
abiDecode 31131 ops/sec (±8.26%) 30419 ops/sec (±8.89%) 0.98
sign 1636 ops/sec (±3.71%) 1656 ops/sec (±4.08%) 1.01
verify 382 ops/sec (±0.49%) 373 ops/sec (±0.78%) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.