This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof web3 !== 'undefined') { | |
web3 = new Web3(web3.currentProvider); | |
} else { | |
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3'); | |
const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); | |
/* | |
* Creating account | |
*/ | |
const passphrase = 'my-super-secret-passphrase'; // Get the passphrase from HTML form or any other way | |
web3.personal.newAccount(passphrase, (error, address) => { | |
user.setAddress(address); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Web3 = require('web3'); | |
const SignerProvider = require('ethjs-provider-signer'); | |
const EthereumTx = require('ethereumjs-tx'); | |
const keystore = require('../lib/keystore'); | |
const provider = new SignerProvider('http://localhost:8545', { | |
signTransaction(rawTx, cb) { | |
const { from } = rawTx; | |
const privateKey = keystore.getPrivateKeyByAddress(from); // Load user's private key from your own keystore | |
const privateKeyHex = Buffer.from(privateKey, 'hex'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const str1 = 'This is an example to test cosine similarity between two strings'; | |
const str2 = 'This example is testing cosine similatiry for given two strings'; | |
// | |
// Preprocess strings and combine words to a unique collection | |
// | |
const str1Words = str1.trim().split(' ').map(omitPunctuations).map(toLowercase); | |
const str2Words = str2.trim().split(' ').map(omitPunctuations).map(toLowercase); | |
const allWordsUnique = Array.from(new Set(str1Words.concat(str2Words))); |