Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't execute batchRequest with privateKey #2708

Closed
rstormsf opened this issue Apr 19, 2019 · 1 comment · Fixed by #2796
Closed

Can't execute batchRequest with privateKey #2708

rstormsf opened this issue Apr 19, 2019 · 1 comment · Fixed by #2796
Labels
Bug Addressing a bug
Projects

Comments

@rstormsf
Copy link

rstormsf commented Apr 19, 2019

Description

const Web3 = require('web3')
const {numberToHex, toWei, toHex} = require('web3-utils')
const web3 = new Web3('https://kovan.infura.io')

async function main() {
  const acc = web3.eth.accounts.wallet.add(process.env.KEY)
  const cb = number => {
    console.log(number, 'callback from batch tx')
  }
  const batch = new web3.BatchRequest()
  let i = 0
  const tx = web3.eth.sendTransaction.request(
    {
      from: acc.address,
      to: '0x0039f22efb07a647557c7c5d17854cfd6d489ef3',
      gas: numberToHex(21000),
      gasPrice: toWei('1', 'gwei'),
      value: toWei('2'),
      data: toHex('peppersec.com')
    },
    cb.bind(this, i)
  )
  i++
  batch.add(tx)
  await batch.execute()

}
main()

Expected behavior

should send batch request using sendRawTx RPC method if used with privateKey

Actual behavior

(node:47721) UnhandledPromiseRejectionWarning: Error: BatchRequest error: ["Response should be of type Array but is: object"]
at /node_modules/web3-providers/dist/web3-providers.cjs.js:824:17
at process._tickCallback (internal/process/next_tick.js:68:7)

The response object from web3-providers/dist/web3-providers.cjs.js:824:17:

response { jsonrpc: '2.0',
  id: 0,
  error:
   { code: -32601,
     message:
      'The method eth_sendTransaction does not exist/is not available' } }

I think it should sign tx, increment nonce and use sendRaw rpc method behind the scenes

Versions

  • web3.js: 1.0.0-beta.52
  • nodejs: v10.15.3
@nivida nivida added the Bug Addressing a bug label Apr 19, 2019
@nivida nivida added this to Accepted To Do's in 1.0 Apr 19, 2019
@PeterTheOne
Copy link
Contributor

Related #1321

@nivida nivida moved this from To Do's to In progress in 1.0 May 8, 2019
1.0 automation moved this from In progress to Done May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
No open projects
1.0
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants