Skip to content

Commit 254caed

Browse files
Improved step 30
1 parent c3690e5 commit 254caed

File tree

9 files changed

+9789
-3704
lines changed

9 files changed

+9789
-3704
lines changed

step30_web3_utils/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
# Node packages
12
node_modules
2-
*.js
3+
4+
# Build files created by TypeScript Compiler
5+
*.js

step30_web3_utils/index.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
import { Utils } from './utils';
1+
import Web3 from "web3";
22

3-
const utils : Utils = new Utils();
3+
const network = "mainnet";
4+
const INFURA_PROJECT_ID = "INFURA_PROJECT_ID";
5+
const RPC_ENDPOINT = `https://${network}.infura.io/v3/${INFURA_PROJECT_ID}`;
46

5-
// get avg gas price of the network
6-
utils.getAvgGasPrice().then((res)=>console.log('Avg gas price on network in ether -------',res))
7+
const web3 = new Web3(RPC_ENDPOINT);
78

8-
//sha3 hashing
9-
utils.hashing('hello world').then((res)=>console.log('hash -------',res))
9+
(async () => {
10+
// #1
11+
const avgGasPrice = web3.utils.fromWei(await web3.eth.getGasPrice(), "ether");
12+
console.log("Average Gas Price ==>", avgGasPrice, "ETH");
1013

11-
//solidity sha3 hashing
12-
utils.Solidityhashing('hello world').then((res)=>console.log('Solidity hash -------',res))
14+
// #2
15+
const phrase = "DApp is Fun";
16+
const hash = web3.utils.sha3(phrase);
17+
console.log(`Hash of "${phrase}" ==>`, hash);
1318

14-
//generate a random hex value. Enter the byte size in the function parameter
15-
utils.generateRandomHex(4).then((res)=>console.log('random hex -------',res))
19+
// #3
20+
const hash2 = web3.utils.soliditySha3(phrase);
21+
console.log(`Hash of "${phrase}" ==>`, hash2);
22+
23+
// #4
24+
const randomHex = web3.utils.randomHex(16);
25+
console.log("Random Hex of size 16 ==>", randomHex);
26+
})();

0 commit comments

Comments
 (0)