@tillicollaps так наглядней(завернуть код/текст лога между ``` и ```):
[12:48:59.316] Language version set to 8.6.0 [12:48:59.316] Added module random-bytes, * [12:48:59.316] Added module crypto-js, * [12:48:59.316] Added function zn3wcsjeb0i [12:48:59.317] Added function mrdpsmegoa [12:48:59.317] Added function ckpy0hlps1m [12:48:59.317] Added function 4lahd6rg91r [12:48:59.317] Added function xoy9wg5h9tf [12:48:59.317] Added function pu0modlurnh [12:48:59.317] Added function oc24eucphb [12:48:59.317] Added function ht0zrxogbbl [12:48:59.317] ------------------------------------------------------------------ [12:48:59.317] Starting Node.js 8.6.0 [12:48:59.318] Installed distr not found [12:48:59.318] Hash b3a0 [12:48:59.318] Suffix Ff0F [12:48:59.328] Getting url http://bablosoft.com/distr/Embedded/Node/8.6.0/distr.x64.zip [12:49:08.624] Writting to C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.node.8.6.0.zip [12:49:08.631] Extracting to folder C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F [12:49:12.924] package.json file content { "dependencies": { "crypto-js": "", "random-bytes": "" } } [12:49:12.925] npm install with C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/node.exe [12:49:15.442] Npm install log standart added 2 packages in 1.536s [12:49:15.443] Npm install log error npm info it worked if it ends with ok npm verb cli [ 'C:\InstaDirectReger\appsremote\InstaDirectReger\SID79143c5f\engine\e\cache.Ff0F\distr\node.exe', npm verb cli 'C:\InstaDirectReger\appsremote\InstaDirectReger\SID79143c5f\engine\e\cache.Ff0F\distr\node_modules\npm\bin\npm-cli.js', npm verb cli 'install', npm verb cli '--loglevel', npm verb cli 'verbose' ] npm info using npm@5.3.0 npm info using node@v8.6.0 npm verb npm-session a3ffa3be135efc23 npm info lifecycle @~preinstall: @ npm http fetch GET 304 https://registry.npmjs.org/crypto-js 348ms (from cache) npm http fetch GET 304 https://registry.npmjs.org/random-bytes 341ms (from cache) npm verb correctMkdir C:\Users\Администратор\AppData\Roaming\npm-cache_locks correctMkdir not in flight; initializing npm verb lock using C:\Users\Администратор\AppData\Roaming\npm-cache_locks\staging-50d3306ebb989cc3.lock for C:\InstaDirectReger\appsremote\InstaDirectReger\SID79143c5f\engine\e\cache.Ff0F\distr\node_modules.staging npm info lifecycle crypto-js@4.0.0~preinstall: crypto-js@4.0.0 npm info lifecycle random-bytes@1.0.0~preinstall: random-bytes@1.0.0 npm info linkStuff crypto-js@4.0.0 npm verb linkBins crypto-js@4.0.0 npm verb linkMans crypto-js@4.0.0 npm info linkStuff random-bytes@1.0.0 npm verb linkBins random-bytes@1.0.0 npm verb linkMans random-bytes@1.0.0 npm info lifecycle crypto-js@4.0.0~install: crypto-js@4.0.0 npm info lifecycle random-bytes@1.0.0~install: random-bytes@1.0.0 npm info lifecycle crypto-js@4.0.0~postinstall: crypto-js@4.0.0 npm info lifecycle random-bytes@1.0.0~postinstall: random-bytes@1.0.0 npm verb unlock done using C:\Users\Администратор\AppData\Roaming\npm-cache_locks\staging-50d3306ebb989cc3.lock for C:\InstaDirectReger\appsremote\InstaDirectReger\SID79143c5f\engine\e\cache.Ff0F\distr\node_modules.staging npm info linkStuff !invalid#1 npm verb linkBins !invalid#1 npm verb linkMans !invalid#1 npm info lifecycle undefined~install: undefined npm info lifecycle undefined~postinstall: undefined npm info lifecycle undefined~prepublish: undefined npm info lifecycle undefined~prepare: undefined npm verb exit [ 0, true ] npm info ok [12:49:15.443] Deleting functions and files [12:49:15.443] Removing directory C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/lib/custom [12:49:15.444] Installing functions and files [12:49:15.444] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/lib/custom/4lahd6rg91r.js [12:49:15.445] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/lib/custom/zn3wcsjeb0i.js [12:49:15.446] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/lib/custom/ckpy0hlps1m.js [12:49:15.446] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/lib/custom/pu0modlurnh.js [12:49:15.448] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/lib/custom/mrdpsmegoa.js [12:49:15.448] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/lib/custom/oc24eucphb.js [12:49:15.449] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/lib/custom/xoy9wg5h9tf.js [12:49:15.449] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F/distr/lib/custom/ht0zrxogbbl.js [12:49:15.450] Renaming directory C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F -> C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/b3a0.Ff0F [12:49:15.450] Failed to move folder [12:49:15.450] Autoclean current folder becuase of error C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/b3a0.Ff0F [12:49:15.450] Autoclean distr becuase of error e/cache.node.8.6.0.zip [12:49:15.450] Autoclean current cache C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F [12:49:16.146] Language version set to 8.6.0 [12:49:16.146] Added module random-bytes, * [12:49:16.146] Added module crypto-js, * [12:49:16.147] Added function zn3wcsjeb0i [12:49:16.147] Added function mrdpsmegoa [12:49:16.147] Added function ckpy0hlps1m [12:49:16.147] Added function 4lahd6rg91r [12:49:16.147] Added function xoy9wg5h9tf [12:49:16.148] Added function pu0modlurnh [12:49:16.148] Added function oc24eucphb [12:49:16.148] Added function ht0zrxogbbl [12:49:16.148] ------------------------------------------------------------------ [12:49:16.148] Starting Node.js 8.6.0 [12:49:16.149] Installed distr not found [12:49:16.149] Hash b3a0 [12:49:16.149] Suffix Jbps [12:49:16.150] Getting url http://bablosoft.com/distr/Embedded/Node/8.6.0/distr.x64.zip [12:49:23.347] Writting to C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.node.8.6.0.zip [12:49:23.354] Extracting to folder C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps [12:49:27.618] package.json file content { "dependencies": { "crypto-js": "", "random-bytes": "" } } [12:49:27.618] npm install with C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/node.exe [12:49:30.74] Npm install log standart added 2 packages in 1.517s [12:49:30.75] Npm install log error npm info it worked if it ends with ok npm verb cli [ 'C:\InstaDirectReger\appsremote\InstaDirectReger\SID79143c5f\engine\e\cache.Jbps\distr\node.exe', npm verb cli 'C:\InstaDirectReger\appsremote\InstaDirectReger\SID79143c5f\engine\e\cache.Jbps\distr\node_modules\npm\bin\npm-cli.js', npm verb cli 'install', npm verb cli '--loglevel', npm verb cli 'verbose' ] npm info using npm@5.3.0 npm info using node@v8.6.0 npm verb npm-session 6647638db65458e3 npm info lifecycle @~preinstall: @ npm http fetch GET 304 https://registry.npmjs.org/crypto-js 295ms (from cache) npm http fetch GET 304 https://registry.npmjs.org/random-bytes 292ms (from cache) npm verb correctMkdir C:\Users\Администратор\AppData\Roaming\npm-cache_locks correctMkdir not in flight; initializing npm verb lock using C:\Users\Администратор\AppData\Roaming\npm-cache_locks\staging-09dc2af04070ca14.lock for C:\InstaDirectReger\appsremote\InstaDirectReger\SID79143c5f\engine\e\cache.Jbps\distr\node_modules.staging npm info lifecycle crypto-js@4.0.0~preinstall: crypto-js@4.0.0 npm info lifecycle random-bytes@1.0.0~preinstall: random-bytes@1.0.0 npm info linkStuff crypto-js@4.0.0 npm verb linkBins crypto-js@4.0.0 npm verb linkMans crypto-js@4.0.0 npm info linkStuff random-bytes@1.0.0 npm verb linkBins random-bytes@1.0.0 npm verb linkMans random-bytes@1.0.0 npm info lifecycle crypto-js@4.0.0~install: crypto-js@4.0.0 npm info lifecycle random-bytes@1.0.0~install: random-bytes@1.0.0 npm info lifecycle crypto-js@4.0.0~postinstall: crypto-js@4.0.0 npm info lifecycle random-bytes@1.0.0~postinstall: random-bytes@1.0.0 npm verb unlock done using C:\Users\Администратор\AppData\Roaming\npm-cache_locks\staging-09dc2af04070ca14.lock for C:\InstaDirectReger\appsremote\InstaDirectReger\SID79143c5f\engine\e\cache.Jbps\distr\node_modules.staging npm info linkStuff !invalid#1 npm verb linkBins !invalid#1 npm verb linkMans !invalid#1 npm info lifecycle undefined~install: undefined npm info lifecycle undefined~postinstall: undefined npm info lifecycle undefined~prepublish: undefined npm info lifecycle undefined~prepare: undefined npm verb exit [ 0, true ] npm info ok [12:49:30.75] Deleting functions and files [12:49:30.75] Removing directory C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/lib/custom [12:49:30.76] Installing functions and files [12:49:30.76] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/lib/custom/4lahd6rg91r.js [12:49:30.77] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/lib/custom/zn3wcsjeb0i.js [12:49:30.77] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/lib/custom/ckpy0hlps1m.js [12:49:30.78] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/lib/custom/pu0modlurnh.js [12:49:30.80] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/lib/custom/mrdpsmegoa.js [12:49:30.80] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/lib/custom/oc24eucphb.js [12:49:30.81] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/lib/custom/xoy9wg5h9tf.js [12:49:30.81] Installing function C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps/distr/lib/custom/ht0zrxogbbl.js [12:49:30.81] Renaming directory C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps -> C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/b3a0.Jbps [12:49:30.82] Failed to move folder [12:49:30.82] Autoclean [12:49:30.83] Not modified C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Ff0F for 21 seconds [12:49:30.83] Not modified C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbps for 6 seconds [12:49:30.83] Autoclean current folder becuase of error C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/b3a0.Jbps [12:49:30.83] Autoclean distr becuase of error e/cache.node.8.6.0.zip [12:49:30.83] Autoclean current cache C:/InstaDirectReger/appsremote/InstaDirectReger/SID79143c5f/engine/e/cache.Jbpsпроблема node js
-
подскажите пожалуйста в чем моя ошибка, вот код:
const { Web3 } = require('web3'); await(new Promise((resolve, reject) => { // Создайте экземпляр Web3, указав URL-адрес RPC-сервера Polygon const web3 = new Web3('https://polygon.llamarpc.com'); // Замените 'txHash' на хеш вашей транзакции const txHash = '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131'; // Замените на фактический хеш вашей транзакции try { // Получите информацию о транзакции с использованием промиса const receipt = web3.eth.getTransactionReceipt(txHash); if (receipt === null) { tx_status = "pending"; console.log('Транзакция пока не подтверждена'); } else { console.log('Транзакция подтверждена'); if (receipt.status === "1n") { tx_status = "success" } else { tx_status = "fail" } [[TX_STATUS]] = tx_status; [[RECEIPT]] = receipt; console.log([[TX_STATUS]], [[RECEIPT]]); //console.log('Статус транзакции:', [[TX_STATUS]]); // '0x1' для успешной транзакции, '0x0' для неуспешной } } catch (error) { console.error('Ошибка при получении информации о транзакции:', error); } resolve() }));но нет переменной receipt, вместо нее в лог выводится {}, или же вообще ничего, то есть по идее скрипт не успевает обработать запрос полностью, я пробовал синхронизировать различными методами, вроде как решение проблемы добавить в строку
const receipt = web3.eth.getTransactionReceipt(txHash);await, но тогда получаем ошибку
const receipt =await web3.eth.getTransactionReceipt(txHash); ^^^^^ SyntaxError: await is only valid in async functions and the top level bodies of modulesпробовал синхронизировать и многими другими способами, но безуспешно, например:
const { Web3 } = require('web3'); async function getTransactionReceipt() { return new Promise(async (resolve, reject) => { try { // Создайте экземпляр Web3, указав URL-адрес RPC-сервера Polygon const web3 = new Web3('https://polygon.llamarpc.com'); // Замените 'txHash' на хеш вашей транзакции const txHash = '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131'; // Замените на фактический хеш вашей транзакции // Получите информацию о транзакции с использованием промиса const receipt = await web3.eth.getTransactionReceipt(txHash); console.log(receipt); resolve(); } catch (error) { console.error('Ошибка при получении информации о транзакции:', error); reject(error); } }); } getTransactionReceipt().then(() => { // Ваш промис был разрешен }).catch((error) => { // Произошла ошибка в промисе }); -
@themarket попробуйте так
const { Web3 } = require('web3'); // Создайте экземпляр Web3, указав URL-адрес RPC-сервера Polygon const web3 = new Web3('https://polygon.llamarpc.com'); // Замените 'txHash' на хеш вашей транзакции const txHash = '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131'; // Замените на фактический хеш вашей транзакции try { // Получите информацию о транзакции с использованием промиса const receipt = await web3.eth.getTransactionReceipt(txHash); if (receipt === null) { tx_status = "pending"; console.log('Транзакция пока не подтверждена'); } else { console.log('Транзакция подтверждена'); if (receipt.status === "1n") { tx_status = "success" } else { tx_status = "fail" } [[TX_STATUS]] = tx_status; [[RECEIPT]] = receipt; console.log([[TX_STATUS]], [[RECEIPT]]); //console.log('Статус транзакции:', [[TX_STATUS]]); // '0x1' для успешной транзакции, '0x0' для неуспешной } } catch (error) { console.error('Ошибка при получении информации о транзакции:', error); } -
@UserTrue Поток №1 : Транзакция подтверждена
Поток №1 : Node process stopped. - ваш код выводит в логчуть изменил его и добавил после
const receipt = await web3.eth.getTransactionReceipt(txHash); console.log(receipt)теперь в логе
Поток №1 : undefined
Поток №1 : Node process stopped. -
@themarket said in проблема node js:
@UserTrue Поток №1 : Транзакция подтверждена
Поток №1 : Node process stopped. - ваш код выводит в логЗначит в целом с кодом все нормально, проблема не с асинхронностью. И я не тестировад код, исправил только визуально ваши проблемы с асинхронным кодом
-
@themarket said in проблема node js:
чуть изменил его и добавил после
const receipt = await web3.eth.getTransactionReceipt(txHash);
console.log(receipt)теперь в логе
Поток №1 : undefined
Поток №1 : Node process stopped.Скорей всего там какой-то сложный объект и он не может его сериализовать, чтобы вывести в лог БАСа. Поэтому не пытайтесь это сделать или передать его в переменную БАС, берите из него только нужные данные.
const { Web3 } = require('web3'); // Создайте экземпляр Web3, указав URL-адрес RPC-сервера Polygon const web3 = new Web3('https://polygon.llamarpc.com'); // Замените 'txHash' на хеш вашей транзакции const txHash = '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131'; // Замените на фактический хеш вашей транзакции let tx_status try { // Получите информацию о транзакции с использованием промиса const receipt = await web3.eth.getTransactionReceipt(txHash); if (receipt === null) { tx_status = "pending"; console.log('Транзакция пока не подтверждена'); } else { console.log('Транзакция подтверждена'); if (receipt.status === "1n") { tx_status = "success" } else { tx_status = "fail" } [[TX_STATUS]] = tx_status; //console.log('Статус транзакции:', [[TX_STATUS]]); // '0x1' для успешной транзакции, '0x0' для неуспешной } } catch (error) { console.error('Ошибка при получении информации о транзакции:', error); } -
@UserTrue в receipt в формате json, мне оттуда нужен result, он в формате bigInt
если я сделаю
console.log('Статус:', receipt.status);то получу в лог Поток №1 : Статус:
бигинт как-то по-особенному надо выводить?сам json:
{ blockHash: '0x060f5717dff435edd16df0c9be20a01b3eb7e7d8e35cdd5b0b658031c5d69496', blockNumber: 48002943n, cumulativeGasUsed: 7263908n, effectiveGasPrice: 91377342858n, from: '0x354ef3cc21485c0ff2032291884e40c3415e550a', gasUsed: 118759n, logs: [ { address: '0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789', topics: [Array], data: '0x', blockNumber: 48002943n, transactionHash: '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131', transactionIndex: 37n, blockHash: '0x060f5717dff435edd16df0c9be20a01b3eb7e7d8e35cdd5b0b658031c5d69496', logIndex: 210n, removed: false }, { address: '0x000031dd6d9d3a133e663660b959162870d755d4', topics: [Array], data: '0x', blockNumber: 48002943n, transactionHash: '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131', transactionIndex: 37n, blockHash: '0x060f5717dff435edd16df0c9be20a01b3eb7e7d8e35cdd5b0b658031c5d69496', logIndex: 211n, removed: false }, { address: '0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789', topics: [Array], data: '0x000000000000000000000000000000000000000000000000000000000000000d0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000002ff2451ac80b3800000000000000000000000000000000000000000000000000000000000240ec', blockNumber: 48002943n, transactionHash: '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131', transactionIndex: 37n, blockHash: '0x060f5717dff435edd16df0c9be20a01b3eb7e7d8e35cdd5b0b658031c5d69496', logIndex: 212n, removed: false }, { address: '0x0000000000000000000000000000000000001010', topics: [Array], data: '0x000000000000000000000000000000000000000000000000002ff2451ac80b380000000000000000000000000000000000000000000009dee182b0977e91b8a900000000000000000000000000000000000000000000000052bf15fc8b52f4740000000000000000000000000000000000000000000009dee152be5263c9ad7100000000000000000000000000000000000000000000000052ef0841a61affac', blockNumber: 48002943n, transactionHash: '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131', transactionIndex: 37n, blockHash: '0x060f5717dff435edd16df0c9be20a01b3eb7e7d8e35cdd5b0b658031c5d69496', logIndex: 213n, removed: false }, { topics: [Array], data: '0x000000000000000000000000000000000000000000000000000ca85208443400000000000000000000000000000000000000000000000000532c096e467fde24000000000000000000000000000000000000000000006e45018836a104044e3a000000000000000000000000000000000000000000000000531f611c3e3baa24000000000000000000000000000000000000000000006e450194def30c48823a', blockNumber: 48002943n, transactionHash: '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131', transactionIndex: 37n, blockHash: '0x060f5717dff435edd16df0c9be20a01b3eb7e7d8e35cdd5b0b658031c5d69496', removed: false } ], logsBloom: '0x10000000000000000000000000000000000000000000004000000000000400000008000000000002000200110000000000108000000000000000020000000000000000000000000000000002000000800000000000000000000300000000000000000400080000000400040000000000000000000000004080840000000000000000000b00000000010002000000000000000000000000000001000000000000200000000400000000400020000000000000001000000000000002000000004000000000000008000001000400010008004008000000800000108000000000000000010000000000000000000000000000000000000000000000000000100000', status: 1n, to: '0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789', transactionHash: '0xf9c36be52a6bd83d640f5d007740a053be18775302576503b1591ec8af1a6131', transactionIndex: 37n, type: 2n -
@themarket said in проблема node js:
он в формате bigInt
его нужно привести к строке, BigInt это не просто число или строка
-
@themarket вряд-ли это проблема бас, скорей всего nodejs не может привести этот объект к json, а бас с нодой данными в json обменивается