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

Commit c1f8a17

Browse files
tiny edit at ethers.md
1 parent beae979 commit c1f8a17

File tree

1 file changed

+38
-38
lines changed
  • docs/docs/guides/migration_from_other_libs

1 file changed

+38
-38
lines changed

docs/docs/guides/migration_from_other_libs/ethers.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ async function getBlockNumber() {
2828
const provider = new ethers.providers.JsonRpcProvider(url);
2929

3030
// in v6:
31-
const provider = new ethers.JsonRpcProvider(url);
31+
const provider = new ethers.JsonRpcProvider(url);
3232

33-
const ts = provider.getBlockNumber();
34-
ts.then(console.log);
33+
const ts = provider.getBlockNumber();
34+
ts.then(console.log);
3535
}
3636
// outputs something like: 18561956
3737
getBlockNumber();
@@ -43,9 +43,9 @@ With web3.js:
4343
import { Web3 } from 'web3';
4444

4545
async function getBlockNumber() {
46-
const web3 = new Web3(url);
47-
const ts = web3.eth.getBlockNumber();
48-
ts.then(console.log);
46+
const web3 = new Web3(url);
47+
const ts = web3.eth.getBlockNumber();
48+
ts.then(console.log);
4949
}
5050
// outputs something like: 18561956n
5151
getBlockNumber();
@@ -97,13 +97,13 @@ In ethers.js:
9797

9898
```typescript
9999
async function createWallet() {
100-
const wallet = new ethers.Wallet(
101-
// A private key that you might had generated with:
102-
// ethers.Wallet.createRandom().privateKey
103-
privateKey,
104-
);
100+
const wallet = new ethers.Wallet(
101+
// A private key that you might had generated with:
102+
// ethers.Wallet.createRandom().privateKey
103+
privateKey,
104+
);
105105

106-
console.log(wallet.address);
106+
console.log(wallet.address);
107107
}
108108
// outputs: 0x6f7D735dFB514AA1778E8D97EaCE72BfECE71865
109109
createWallet();
@@ -113,13 +113,13 @@ With web3.js:
113113

114114
```typescript
115115
async function createWallet() {
116-
const web3 = new Web3();
117-
const wallet = web3.eth.accounts.wallet.add(
118-
// you can generate a private key using web3.eth.accounts.create().privateKey
119-
privateKey,
120-
);
116+
const web3 = new Web3();
117+
const wallet = web3.eth.accounts.wallet.add(
118+
// you can generate a private key using web3.eth.accounts.create().privateKey
119+
privateKey,
120+
);
121121

122-
console.log(wallet[0].address);
122+
console.log(wallet[0].address);
123123
}
124124
// outputs: 0x6f7D735dFB514AA1778E8D97EaCE72BfECE71865
125125
createWallet();
@@ -179,23 +179,23 @@ And for the case when you did not add the private key early, and so the `from` w
179179

180180
```typescript
181181
async function sendTransaction() {
182-
const web3 = new Web3('http://localhost:8545');
182+
const web3 = new Web3('http://localhost:8545');
183183

184-
// The method web3.eth.sendTransaction is helpful if you are using a browser-injected provider like metamask.
185-
// Or, if you are using a local dev node like ganache; and you have some accounts already unlocked at the node.
186-
// And this is how you would get the first unlocked account from a local node (not advised for production or even on test node to use unlock accounts on the node).
187-
const account = (await web3.eth.getAccounts())[0];
184+
// The method web3.eth.sendTransaction is helpful if you are using a browser-injected provider like metamask.
185+
// Or, if you are using a local dev node like ganache; and you have some accounts already unlocked at the node.
186+
// And this is how you would get the first unlocked account from a local node (not advised for production or even on test node to use unlock accounts on the node).
187+
const account = (await web3.eth.getAccounts())[0];
188188

189-
// Alternative to the above, here is how to add wallet to be used as a signer later:
190-
const wallet = web3.eth.accounts.wallet.add(privateKey);
191-
const account = wallet[0].address;
192-
193-
const tx = await web3.eth.sendTransaction({
194-
from: account,
195-
to: '0x92d3267215Ec56542b985473E73C8417403B15ac',
196-
value: web3.utils.toWei('0.00000000001', 'ether'),
197-
});
198-
console.log(tx);
189+
// Alternative to the above, here is how to add wallet to be used as a signer later:
190+
const wallet = web3.eth.accounts.wallet.add(privateKey);
191+
const account = wallet[0].address;
192+
193+
const tx = await web3.eth.sendTransaction({
194+
from: account,
195+
to: '0x92d3267215Ec56542b985473E73C8417403B15ac',
196+
value: web3.utils.toWei('0.00000000001', 'ether'),
197+
});
198+
console.log(tx);
199199
}
200200

201201
sendTransaction();
@@ -399,18 +399,18 @@ Handling events with ethers.js:
399399

400400
```typescript
401401
contract.on('SomeEvent', (arg1, arg2, event) => {
402-
// event handling
402+
// event handling
403403
});
404404
```
405405

406406
With web3.js:
407407

408408
```typescript
409409
const event = contract.events.SomeEvent({
410-
filter: {
411-
filter: { val: 100 },
412-
},
413-
fromBlock: 0,
410+
filter: {
411+
filter: { val: 100 },
412+
},
413+
fromBlock: 0,
414414
});
415415

416416
event.on('data', resolve);

0 commit comments

Comments
 (0)