Skip to content

Commit 064de23

Browse files
committed
typo fixes in the docs
1 parent e39d7e3 commit 064de23

File tree

2 files changed

+157
-3
lines changed

2 files changed

+157
-3
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Note: This is fork of https://www.npmjs.com/package/@truffle/hdwallet-provider w
88
## Install
99

1010
```
11-
$ npm install web3-provide-nodejs
11+
$ npm install web3-provider-nodejs
1212
```
1313

1414
```
15-
$ yarn add web3-provide-nodejs
15+
$ yarn add web3-provider-nodejs
1616
```
1717

1818
## Requirements
@@ -48,7 +48,7 @@ Parameters:
4848
Some examples can be found below:
4949

5050
```javascript
51-
const Web3NodejsProvider = require("web3-nodejs-provier");
51+
const Web3NodejsProvider = require("web3-nodejs-provider");
5252
const Web3 = require("web3");
5353
const mnemonicPhrase = "mountains supernatural bird..."; // 12 word mnemonic
5454

dist/README.md

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# web3-provider-nodejs
2+
HD Wallet-enabled Web3 provider. Use it to sign transactions for addresses derived from a 12 or 24 word mnemonic.
3+
4+
Note: This is fork of https://www.npmjs.com/package/@truffle/hdwallet-provider with changes:
5+
- Explicitly provider `private` keys, `mnemomic` (or both)
6+
- Removed `shared Nonce` option
7+
- `provider.stop` is handled by environment, needless to call `provider.stop()`
8+
## Install
9+
10+
```
11+
$ npm install web3-provider-nodejs
12+
```
13+
14+
```
15+
$ yarn add web3-provider-nodejs
16+
```
17+
18+
## Requirements
19+
```
20+
Node >= 12
21+
Web3 ^1.2.0
22+
```
23+
24+
## General Usage
25+
26+
You can use this provider wherever a Web3 provider is needed. Suitable for use in `Nodejs`, `Deno` runtimes where
27+
`window.ethereum` is not available.
28+
29+
### Instantiation
30+
31+
You can instantiate `Web3NodejsProvider` with options passed in an object with
32+
named keys. You can specify the following options in your object:
33+
34+
Parameters:
35+
36+
| Parameter | Type | Default | Required | Description |
37+
| ------ | ---- | ------- | ----------- | ----------- |
38+
| `mnemonic` | `object\|string` | `null` | [ ] | Object containing `phrase` and `password` (optional) properties. `phrase` is a 12 word mnemonic string which addresses are created from. Alternately the value for mnemonic can be a string with your mnemonic phrase. |
39+
| `privateKeys` | `string[]` | `null` | [ ] | Array containing 1 or more private keys. |
40+
| `providerOrUrl` | `string\|object` | `null` | [x] | URI or Ethereum client to send all other non-transaction-related Web3 requests |
41+
| `addressIndex` | `number` | `0` | [ ] | If specified, will tell the provider to manage the address at the index specified |
42+
| `numberOfAddresses` | `number` | `1` | [ ] | If specified, will create `numberOfAddresses` addresses when instantiated |
43+
| `shareNonce` | `boolean` | `true` | [ ] | If `false`, a new WalletProvider will track its own nonce-state |
44+
| `derivationPath` | `string` | `"m/44'/60'/0'/0/"` | [ ] | If specified, will tell the wallet engine what derivation path should use to derive addresses. |
45+
| `pollingInterval` | `number` | `4000` | [ ] | If specified, will tell the wallet engine to use a custom interval when polling to track blocks. Specified in milliseconds. |
46+
| `chainId` | `number\|string` | `undefined` | [ ] | Specify to enable signed transactions that are EIP-155 compliant for major chains. |
47+
48+
Some examples can be found below:
49+
50+
```javascript
51+
const Web3NodejsProvider = require("web3-nodejs-provider");
52+
const Web3 = require("web3");
53+
const mnemonicPhrase = "mountains supernatural bird..."; // 12 word mnemonic
54+
55+
let provider = new Web3NodejsProvider({
56+
mnemonic: {
57+
phrase: mnemonicPhrase
58+
},
59+
providerOrUrl: "http://localhost:8545"
60+
});
61+
62+
// Or, alternatively pass in a zero-based address index.
63+
provider = new Web3NodejsProvider({
64+
mnemonic: mnemonicPhrase,
65+
providerOrUrl: "http://localhost:8545",
66+
addressIndex: 5
67+
});
68+
69+
// Or, use your own hierarchical derivation path
70+
provider = new Web3NodejsProvider({
71+
mnemonic: mnemonicPhrase,
72+
providerOrUrl: "http://localhost:8545",
73+
numberOfAddresses: 1,
74+
shareNonce: true,
75+
derivationPath: "m/44'/137'/0'/0/"
76+
});
77+
78+
// To make HDWallet less "chatty" over JSON-RPC,
79+
// configure a higher value for the polling interval.
80+
provider = new Web3NodejsProvider({
81+
mnemonic: {
82+
phrase: mnemonicPhrase
83+
},
84+
providerOrUrl: "http://localhost:8545",
85+
pollingInterval: 8000
86+
});
87+
88+
// HDWalletProvider is compatible with Web3. Use it at Web3 constructor, just like any other Web3 Provider
89+
const web3 = new Web3(provider);
90+
91+
// Or, if web3 is alreay initialized, you can call the 'setProvider' on web3, web3.eth, web3.shh and/or web3.bzz
92+
web3.setProvider(provider)
93+
94+
// ...
95+
// Write your code here.
96+
// ...
97+
98+
// At termination, `provider.engine.stop()' should be called to finish the process elegantly.
99+
provider.engine.stop();
100+
```
101+
102+
**Note: If both mnemonic and private keys are provided, the mnemonic is used.**
103+
104+
### Using the legacy interface (deprecated)
105+
106+
The legacy interface is deprecated and it is recommended to pass options in an
107+
object as detailed above. The following method of passing options is here
108+
primarily to document the interface thoroughly and avoid confusion.
109+
110+
You can specify the following options in the order below.
111+
Pass `undefined` if you want to omit a parameter.
112+
113+
Parameters:
114+
115+
| Parameter | Type | Default | Required | Description |
116+
| ------ | ---- | ------- | ----------- | ----------- |
117+
| `mnemonic`/`privateKeys` | `string`/`string[]` | `null` | [x] | 12 word mnemonic which addresses are created from or array of private keys. |
118+
| `providerOrUrl` | `string\|object` | `null` | [x] | URI or Ethereum client to send all other non-transaction-related Web3 requests |
119+
| `addressIndex` | `number` | `0` | [ ] | If specified, will tell the provider to manage the address at the index specified |
120+
| `numberOfAddresses` | `number` | `1` | [ ] | If specified, will create `numberOfAddresses` addresses when instantiated |
121+
| `shareNonce` | `boolean` | `true` | [ ] | If `false`, a new WalletProvider will track its own nonce-state |
122+
| `derivationPath` | `string` | `"m/44'/60'/0'/0/"` | [ ] | If specified, will tell the wallet engine what derivation path should use to derive addresses. |
123+
| `chainId` | `number\|string` | `undefined` | [ ] | Specify to enable signed transactions that are EIP-155 compliant for major chains. |
124+
125+
Instead of a mnemonic, you can alternatively provide a private key or array of
126+
private keys as the first parameter. When providing an array, `addressIndex`
127+
and `numberOfAddresses` are fully supported.
128+
129+
```javascript
130+
const Web3NodejsProvider = require("web3-nodejs-provider");
131+
//load single private key as string
132+
let provider = new Web3NodejsProvider("3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580", "http://localhost:8545");
133+
134+
// Or, pass an array of private keys, and optionally use a certain subset of addresses
135+
const privateKeys = [
136+
"3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580",
137+
"9549f39decea7b7504e15572b2c6a72766df0281cea22bd1a3bc87166b1ca290",
138+
];
139+
140+
provider = new Web3NodejsProvider(privateKeys, "http://localhost:8545", 0, 2); //start at address_index 0 and load both addresses
141+
```
142+
**NOTE: This is just an example. NEVER hard code production/mainnet private
143+
keys in your code or commit them to git. They should always be loaded from
144+
environment variables or a secure secret management system.**
145+
146+
## Similar work
147+
Compose own providers (Made to work with MetaMask Browser Wallet only): https://github.com/MetaMask/web3-provider-engine
148+
149+
## Support
150+
If you wish to support this project, please do so on:
151+
152+
1. BTC: `3AKZndQ3fgj48emakUXe81dyW7zTJQm7wv`
153+
2. LTC: `MQFsxZ42CD3HEyucM1jj2WM4xbYibYWsVg`
154+
3. ETH: `0xB61ED210326FEb11A1f7048c77c404553fCed702`

0 commit comments

Comments
 (0)