Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
luu-alex committed Nov 23, 2023
1 parent 62382dd commit c36839c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
6 changes: 3 additions & 3 deletions docs/docs/guides/basics/sign_and_send_tx/local_wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import { Web3 } from 'web3';
const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to wallet
const privateKeyString = 'PrivateKey';
const privateKeyString = 'privateKey';
const account = web3.eth.accounts.wallet.add(privateKeyString).get(0);

// Make sure the account has enough eth on balance to send the transaction
Expand Down Expand Up @@ -110,7 +110,7 @@ const { Web3 } = require('web3');
const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to wallet
const privateKeyString = 'PrivateKey';
const privateKeyString = 'privateKey';
const account = web3.eth.accounts.wallet.add(privateKeyString).get(0);

// Make sure the account has enough eth on balance to send the transaction
Expand Down Expand Up @@ -165,7 +165,7 @@ import { Web3 } from 'web3';
const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to wallet
const privateKeyString = 'PrivateKey';
const privateKeyString = 'privateKey';
const account = web3.eth.accounts.wallet.add(privateKeyString).get(0);

// Make sure the account has enough eth on balance to send the transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to the Ethereum node and unlock it
const account = {
privateKey: 'Private key here',
privateKey: 'privateKey',
address: '0xe4beef667408b99053dc147ed19592ada0d77f59',
};

Expand Down Expand Up @@ -64,7 +64,7 @@ const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to the Ethereum node and unlock it
const account = {
privateKey: 'Private key here',
privateKey: 'privateKey',
address: '0xe4beef667408b99053dc147ed19592ada0d77f59',
};

Expand Down Expand Up @@ -116,7 +116,7 @@ const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to the Ethereum node and unlock it
const account = {
privateKey: 'Private key here',
privateKey: 'privateKey',
address: '0xe4beef667408b99053dc147ed19592ada0d77f59',
};

Expand Down Expand Up @@ -170,7 +170,7 @@ const web3 = new Web3(/* PROVIDER*/);

// Second step: add an account to the Ethereum node and unlock it
const account = {
privateKey: 'Private key here',
privateKey: 'privateKey',
address: '0xe4beef667408b99053dc147ed19592ada0d77f59',
};

Expand Down
32 changes: 28 additions & 4 deletions docs/docs/guides/wallet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ The following is a list of web3-eth-account [methods]( /api/web3-eth-accounts/cl
- [decrypt](https://docs.web3js.org/libdocs/Accounts#decrypt)


### Creating a Web3Account with web3 package and signing a message
### Creating a Web3Account with the web3-eth-accounts package and signing a message


``` ts
import web3 from 'web3';
import { create } from 'web3-eth-accounts';


const account = web3.eth.accounts.create();
// the create method returns a Web3Account object. It contains an address and private key and allows you to be able to encrypt, sign and signTransaction.
const account = create();
{
address: '0xbD504f977021b5E5DdccD8741A368b147B3B38bB',
privateKey: 'privateKey',
Expand All @@ -55,9 +58,30 @@ account.sign("hello world");
}

```
### Creating a Web3Account with web3-eth-accounts package and signing a transaction
### import a private key and sign a transaction with the web3 package

``` ts
import Web3 from 'web3';

const web3 = new Web3("provider");

const account = web3.eth.accounts.privateKeyToAccount("privateKey");

signedTransaction = await account.signTransaction({
from: a.address,
to: '0xe4beef667408b99053dc147ed19592ada0d77f59',
value: '0x1',
gas: '300000',
gasPrice: await web3.eth.getGasPrice()
})
> {
messageHash: '0xfad22c3ab5ecbb6eec934a21243ee1866fbbd3786f4e8e8ec631b917ef65174d',
v: '0xf4f6',
r: '0xc0035636d9417f63fdd418bc545190e59b58a4ff921bbf4efebf352dac211f11',
s: '0x4944d746ff12c7bca41f77c8f7d75301cea8b205e021dfde34d09d5bdccc713d',
rawTransaction: '0xf866808477359400830493e094e4beef667408b99053dc147ed19592ada0d77f59018082f4f6a0c0035636d9417f63fdd418bc545190e59b58a4ff921bbf4efebf352dac211f11a04944d746ff12c7bca41f77c8f7d75301cea8b205e021dfde34d09d5bdccc713d',
transactionHash: '0xa3fed275c97abc4a160cd9bef3ec90206686f32821a8fd4e01a04130bff35c1a'
}

```
### Local wallets
Expand Down

0 comments on commit c36839c

Please sign in to comment.