|
1 | | -import { Utils } from './utils'; |
| 1 | +import Web3 from "web3"; |
2 | 2 |
|
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}`; |
4 | 6 |
|
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); |
7 | 8 |
|
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"); |
10 | 13 |
|
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); |
13 | 18 |
|
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