5

I'm currently working on a dapp that requires a backend, and event-listening. I've setup web3js with a infura websocket on the rinkeby network but I'm having a hard time setting up my accounts(using a mnemonic) into web3js.

So right now the event listening works but I can't sign transactions with my mneumonic, and the opposite was the case using truffle-hdwallet-provider.

Here's my file defining the web3js object

const Web3 = require('web3')
require('dotenv').config()

let web3

// const HDWalletProvider = require('truffle-hdwallet-provider')
// const mnemonic = process.env.mneumonic
// const api_key = process.env.infurakey

// const RinkbeyProvider = new HDWalletProvider(mnemonic, 'https://rinkeby.infura.io/'+api_key)
console.log('Using Rinkbey Provider')
web3 = new Web3(new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws'))
// web3 = new Web3(RinkbeyProvider)

module.exports = {
  web3
}

Previously, I was using the HDWalletProvider to to set the web3 object, but since that doesn't work with HTTP (I've tried forking the package, couldn't get it to work) I've had to switch to using the regular websocket constructor.

How can I configure web3 to work with my accounts associated with the mnemonics? is there a package that performs a similar function to truffle-hdwallet-provider but works with websockets?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Luis Osta
  • 144
  • 1
  • 13
  • 2
    Hi @Luis Osta, even i was facing the same issue, i solved it by manually signing transaction. ie. any contract function call should be signed manually. In my case i had ownerOnly function to be called in server side. So i used owner's public and private address to sign. Now i am able to listen to events as well – Pram Nov 06 '18 at 12:00

0 Answers0