我正在使用TronWeb和TronGrid,当我尝试启动时,不知何故,我看到随机完成index.js,有时它完成时出错。
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"
}
}
我应该做什么,以每一个请求完成正确?谢谢!
1条答案
按热度按时间jm81lzqq1#
您没有在tronWeb示例中放置任何API-KEY,因此,每秒的查询/事务非常少,这可能是事务有时工作有时不工作的原因