tronprotocol / tronweb

Javascript API Library for interacting with the TRON Network
MIT License
419 stars 271 forks source link

TronWeb Is not a constructor #542

Open mayorityz opened 1 month ago

mayorityz commented 1 month ago

Hello,

Everytime i try to create a wallet, i get the error, "TronWeb is not a constructor". The tron version is "tronweb": "^6.0.0-beta.3".

` const TronWeb = require('tronweb')

const privateKey = crypto.randomBytes(32).toString('hex')

  const tronWeb = new TronWeb({
    fullHost: 'https://api.trongrid.io',
    headers: { 'TRON-PRO-API-KEY': config.scans.tron.api_key },
    privateKey,
  })
  const account = await tronWeb.createAccount()

  console.log('New wallet created:')
  console.log('Address:', account.address.base58)
  console.log('Private Key:', account.privateKey)

  // IMPORTANT: Make sure to securely store the private key!
  console.log(
    'IMPORTANT: Securely store the private key. Never share it with anyone!',
  )

  return account

`

start940315 commented 1 month ago

We changed default exports to named exports which is started from TronWeb v6. Please use

import { TronWeb } from 'tronweb';

Know more differences from here

mayorityz commented 1 month ago

We changed default exports to named exports which is started from TronWeb v6. Please use


import { TronWeb } from 'tronweb';

Know more differences from here

Wow. It's a largely commonjs project, which means refactoring all the code to fit.

Is it possible to downgrade the package?

start940315 commented 1 month ago

If you don't have enough time to refactor your code. You can use TronWeb@v5.3.2 by using following command:

npm install tronweb@latest