My Image
CoursesQuizzesProblemsContestsSmartBooks
Contest!

No results found

LOGINREGISTER
My ProgressCoursesQuizzesProblemsContestsSmartbooks
Published on 15 Jul 2021
To generate hash of username using cryptographic functions in web3 and Nodejs
Sha3( ), keccak256( ), soliditysha3( ) hashes
img
Rajendra Bisoi
0
Like
306

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!!!!

 

 

 

 

 

Enjoyed the SmartBook?
Like
logo
contact@dapp-world.com
Katraj, Pune, Maharashtra, India - 411048

Follow Us

linkedintwitteryoutubediscordinstagram

Products

  • SmartBooks
  • Courses
  • Quizzes
  • Assessments

Support

  • Contact Us
  • FAQ
  • Privacy Policy
  • T&C

Backed By

ah! ventures

Copyright 2023 - All Rights Reserved.

Recommended from DAppWorld
img
1 May 2021
How to connect Ganache with Metamask and deploy Smart contracts on remix without
Set up your development environment with (Metamask + Ganache + Remix) and skip truffle :)
3 min read
11494
5
img
8 Jul 2021
How to interact with smart contarct from backend node js
call and send functions from backend server side using nodejs
3 min read
8068
2
img
18 Aug 2021
Send transaction with web3 using python
Introduction to web3.py and sending transaction on testnet
3 min read
6215
5
img
5 Aug 2021
Deploy Smart Contract on Polygon POS using Hardhat
how to deploy smart contracts on polygon pos chain using hardhat both mainnet and testnet ?
3 min read
5533
3