when I try to send my transaction using infura I get this error

      "The send transactions "from" field must be defined" 

My problem is my web3 object. When I used Metamask and my app from a Google Chrome page I did't have problem

  App.web3Provider = web3.currentProvider
  web3 = new Web3(web3.currentProvider)

Now, using Truffle, I need to interact with my smart contract without metamask.

I get my web3 from infura.

    App.web3Provider = new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/2a8xxxxxxxxxxxxxxx")
    web3 = new Web3(App.web3Provider)

(UPDATE) Iteraction with my Smart Contract

    const partecipazioneContest = await $.getJSON('File.json')
    App.contracts.PartecipazioneContest = TruffleContract(partecipazioneContest)
    App.partecipazioneContest = await App.contracts.PartecipazioneContest.deployed()

Error when I make the transaction:

  await App.partecipazioneContest.addUser(parameters);

I think my problem is that it does't load my account, so I create my account from my private key and i get the correct addres, but when I try to get my account with getAccount() function the accounts are empty.

    await web3.eth.accounts.privateKeyToAccount('0x33434XXXXXXXXXXX13');
      accounts = acc 
      alert(" getAccounts " + accounts)


How to load my web3 returned from infura with my accounts and all the information that i need to interact with the smart contracts?
I would like to interact with my Smart contract with my wallet on Metamask passing by infura

  • You need to unlock your account on Infura, for Truffle to be able to retrieve it from there. Commented Jul 8, 2020 at 10:28
  • @goodvibration is It possible? I'm reading : "Infura does not support "unlocking" accounts. Instead, users should send already signed raw transactions using eth_sendRawTransaction." infura.io/docs/ethereum/json-rpc/ratelimits Commented Jul 8, 2020 at 11:30
  • No, of course it's not possible, since anyone else connected to that Infura node will be able to use your unlocked account at will. Commented Jul 8, 2020 at 12:10
  • @goodvibration so Dd you have any suggestion? I have had un update for interaction with my Smart Contract. Commented Jul 8, 2020 at 12:21
  • Of course, exactly as suggested to you in the Infura documentation that you've linked above - sign the transaction with your account's private key, and then send the already-signed transaction instead. Commented Jul 8, 2020 at 12:32

1 Answer 1


You can use wrap Web3.js provider with a Truffle HDWalletProvider.

HDWalletProvider wraps the underlying provider and allows you easily use send() with ETH and smart contract transactions with the existing web3.js and contract APIs.

  • Wrap web3 provider with HDWalletProvider
  • Import your private keys to HDWalletProvider
  • Interact with smart contracts and such, set send({from: ...}) to an account that maches the imported private keys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.