I am building a blockchain project in Substrate. I have created a pallet named carpooling and defined some dispatch functions in the pallet. Now I want to call the dispatch function named book-ride from a polkadot js API. Can anyone suggest to me how can I achieve that?
// 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'));
I made a node js app to run this and when I run the node index.js
command I get the following error.
(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.