Loading...
Hello Folks,
So in this session we will be discussing about How to generate hashes of a given username through cryptographic functions using web3 from nodejs.
To do that we need to have web3 Node module installed on our system.
We can do this by running the following code on the cmd
npm install web3
Then let's run our node server. Just run the following code on cmd.
node
Then we need web3 module in our server so run the following code
var Web3 = require('web3')
we will be needing a Blockchain network to create an account so get an rpc url from here
Just click on the link -> Login to your account ->Click on ethereum on left side bar ->create project ->settings->keys->endpoints
and choose your respective testnet rpc url
rpc url it will look like this - https://mainnet.infura.io/v3/your_api_key
var url = 'your RPC url here'
Then run this one
var web3 = new Web3(url)
To generate sha3 hash of an username you can try this code
web3.utils.sha3('Dapp-world') //we have used Dapp-world as username
If you are running this from javascript page so you can use "console.log" to make this visible
console.log(web3.utils.sha3('Dapp-world')) //we have used Dapp-world as username
To generate keccak256 hash of an username you can try this code
console.log(web3.utils.keccak256('Dapp-world')) //we have used username as dapp-world
To generate SoliditySha3 hash of an username you can try this code
console.log(web3.utils.SoliditySha3('Dapp-world'))
To generate randomHex hash of an username you can try this code
this takes byte size for the HEX string as an input e.g. 2 bytes HEX string will result 6 characters preficed with "0x"
console.log(web3.utils.randomHex(1))
For test ethers and link tokens. Click Here
For many more exciting tutorials keep following my username @BlockTalks_Raj
!!!!!HAPPY LEARNING!!!!