首页 > 解决方案 > (节点: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.

标签: javascriptrustsubstratepolkadot

解决方案


推荐阅读