daochild / tronweb-typescript

Typescript support package for tronweb library ^4.x
MIT License
19 stars 5 forks source link

Initialization #3

Closed vekseel closed 2 months ago

vekseel commented 1 year ago

Hello! How to properly create a TronWeb instance? I get an error

image

image

daochild commented 1 year ago

try add type directly like in example ///<reference path="node_modules/@daochild/tronweb-typescript/dist/index.d.ts"/>

Files in test project

{
  "name": "test-npm",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "npm run build-ts",
    "test": "jest --coverage=false --verbose",
    "watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"cyan.bold,green.bold\" \"npm run watch-ts\"",
    "build-ts": "rimraf ./dist && tsc",
    "watch-ts": "tsc -w"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "tronweb": "^5.3.0"
  },
  "devDependencies": {
    "@daochild/tronweb-typescript": "1.1.1",
    "@types/node": "^14.18.59",
    "rimraf": "^5.0.1",
    "ts-node": "^10.9.1",
    "typescript": "5.2.2"
  }
}
{
    "compilerOptions": {
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "module": "commonjs",
        "esModuleInterop": true,
        "target": "es5",
        "noImplicitAny": true,
        "allowJs": true,
        "skipLibCheck": true,
        "sourceMap": true,
        "outDir": "dist",
        "declaration": true,
        "baseUrl": ".",
        "types":  ["node"],
        "lib": [ "esnext", "dom", "es6", "es5", "es2020", "es2022"],
    },
    "exclude": [
        "dist",
        "node_modules"
    ]
}
// Code language: TypeScript

///<reference path="node_modules/@daochild/tronweb-typescript/dist/index.d.ts"/>
import TronWeb from 'tronweb'

const tronweb: TronWeb = new TronWeb({
    fullHost: 'https://api.trongrid.io',
})

console.log(tronweb)
vekseel commented 1 year ago

try add type directly like in example ///<reference path="node_modules/@daochild/tronweb-typescript/dist/index.d.ts"/>

Files in test project

{
  "name": "test-npm",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "npm run build-ts",
    "test": "jest --coverage=false --verbose",
    "watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"cyan.bold,green.bold\" \"npm run watch-ts\"",
    "build-ts": "rimraf ./dist && tsc",
    "watch-ts": "tsc -w"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "tronweb": "^5.3.0"
  },
  "devDependencies": {
    "@daochild/tronweb-typescript": "1.1.1",
    "@types/node": "^14.18.59",
    "rimraf": "^5.0.1",
    "ts-node": "^10.9.1",
    "typescript": "5.2.2"
  }
}
{
    "compilerOptions": {
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "module": "commonjs",
        "esModuleInterop": true,
        "target": "es5",
        "noImplicitAny": true,
        "allowJs": true,
        "skipLibCheck": true,
        "sourceMap": true,
        "outDir": "dist",
        "declaration": true,
        "baseUrl": ".",
        "types":  ["node"],
        "lib": [ "esnext", "dom", "es6", "es5", "es2020", "es2022"],
    },
    "exclude": [
        "dist",
        "node_modules"
    ]
}
// Code language: TypeScript

///<reference path="node_modules/@daochild/tronweb-typescript/dist/index.d.ts"/>
import TronWeb from 'tronweb'

const tronweb: TronWeb = new TronWeb({
    fullHost: 'https://api.trongrid.io',
})

console.log(tronweb)

Unfortunately the same result image image

daochild commented 1 year ago

What tronweb version and typescript?

Updated: Node version? See in documentation.

daochild commented 2 months ago

Update to v1.2.2