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

TronWeb Is not a constructor #542

Open
mayorityz opened this issue Jul 23, 2024 · 3 comments
Open

TronWeb Is not a constructor #542

mayorityz opened this issue Jul 23, 2024 · 3 comments

Comments

@mayorityz
Copy link

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
Copy link
Contributor

start940315 commented Jul 23, 2024

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
Copy link
Author

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@start940315 @mayorityz and others