Tronweb 和 Trongrid 错误:请求失败,状态码为 502

时间:2021-03-25 09:21:04

标签: javascript node.js blockchain solidity

当我尝试以某种方式启动时,我正在使用 TronWeb 和 TronGrid,我看到随机完成 index.js,有时它完成时出错。状态码 502..

PS D:\trontest> node index.js
balance: 6816.72342
PS D:\trontest> node index.js
(node:8144) UnhandledPromiseRejectionWarning: Error: Request failed with status code 502
    at createError (D:\trontest\node_modules\axios\lib\core\createError.js:16:15)
    at settle (D:\trontest\node_modules\axios\lib\core\settle.js:17:12)
    at IncomingMessage.handleStreamEnd (D:\trontest\node_modules\axios\lib\adapters\http.js:260:11)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8144) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:8144) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
PS D:\trontest> node index.js
balance: 6816.72342
PS D:\trontest>

index.js

const TronGrid = require("trongrid");
const TronWeb = require("tronweb");

const tronWeb = new TronWeb({
    fullHost: 'https://api.shasta.trongrid.io'
});

const tronGrid = new TronGrid(tronWeb);
const address = "TE5KZD*******EdwZYJqxWjqjAovvEeGu";

async function  getBalance(adr)  {
    const balance = await tronWeb.trx.getBalance(adr);
    console.log("balance:", balance/1000000);
}
getBalance(address);

package.json

{
  "name": "trontest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "trongrid": "^1.2.6",
    "tronweb": "^3.2.6"
  }
}

对于正确完成的每个请求,我应该怎么做?谢谢!

0 个答案:

没有答案