javascript - (节点:21899)UnhandledPromiseRejectionWarning
问题描述
我正在 Substrate 中构建一个区块链项目。我创建了一个名为carpooling的托盘,并在托盘中定义了一些调度功能。现在我想从 polkadot js API调用名为book-ride的调度函数。谁能建议我如何实现这一目标?
// Import
const { ApiPromise, WsProvider } = require('@polkadot/api');
async function main(){
// Construct
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider,
types: {
DriverOf: {
id: 'u32',
car_no: 'Hash',
location: ('u32', 'u32'),
price: 'u32',
},
CustomerOf: {
id: 'u32',
name: 'Hash',
location: ('u32', 'u32'),
},
}
});
api.tx.carpooling.book_ride(12,45).then(() => {
console.log("success");
}).catch(console.error);
}
main().then(() => console.log('completed'));
我制作了一个节点 js 应用程序来运行它,当我运行node index.js
命令时出现以下错误。
(node:21899) UnhandledPromiseRejectionWarning: TypeError: api.tx.carpooling.book_ride is not a function
at main (/home/knoldus/Carpooling-Chain/app/src/index.js:26:23)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21899) 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: 1)
(node:21899) [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.
解决方案
推荐阅读
- python - 安装时linux终端错误
- c# - ArgumentException:不支持关键字:'persistsecurity info' .NET Core MVC 2.0
- powerpoint - 如何在用户单击或按下任何按钮时删除上一个项目
- linux - 临时屏幕输出会话存储在哪里
- c# - 根据 id 获取绑定对象
- java - 从不同的类调用时,Java repaint() 不起作用
- android - 更改按钮颜色会导致按钮变大
- apache-spark - 如何使用 YARN 客户端模式在 Jupyter 中以交互方式运行 Pyspark?
- sorting - 将 jinja 列表中的值四舍五入
- android - 在从活动移动到片段时实现抽象方法