1
votes

When I want to use the method that is built in substrate based chain together with the custom type i get the following error:

2020-04-13 21:03:01 RPC-CORE: submitAndWatchExtrinsic(extrinsic: Extrinsic): ExtrinsicStatus:: 1002: Verification Error: Execution(ApiError("Could not convert parameter `tx` between node and runtime: Error decoding field Call :: Poe.0")): RuntimeApi("Execution(ApiError(\"Could not convert parameter `tx` between node and runtime: Error de
2020-04-13 21:03:01 DRR: Error: 1002: Verification Error: Execution(ApiError("Could not convert parameter `tx` between node and runtime: Error decoding field Call :: Poe.0")): RuntimeApi("Execution(ApiError(\"Could not convert parameter `tx` between node and runtime: Error 
de
    at RpcCoder._checkError (/c/substrate-mvce/js-cli/node_modules/@polkadot/rpc-provider/coder/index.js:83:13)
    at RpcCoder.decodeResponse (/c/substrate-mvce/js-cli/node_modules/@polkadot/rpc-provider/coder/index.js:46:10)
    at WsProvider.value (/c/substrate-mvce/js-cli/node_modules/@polkadot/rpc-provider/ws/Provider.js:160:90)
    at W3CWebSocket.value [as onmessage] (/c/substrate-mvce/js-cli/node_modules/@polkadot/rpc-provider/ws/Provider.js:140:153)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (/c/substrate-mvce/js-cli/node_modules/yaeti/lib/EventTarget.js:107:17)
    at W3CWebSocket.onMessage (/c/substrate-mvce/js-cli/node_modules/websocket/lib/W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (/c/substrate-mvce/js-cli/node_modules/websocket/lib/W3CWebSocket.js:205:19)
    at WebSocketConnection.emit (events.js:315:20)
    at WebSocketConnection.processFrame (/c/substrate-mvce/js-cli/node_modules/websocket/lib/WebSocketConnection.js:554:26)
    at /c/substrate-mvce/js-cli/node_modules/websocket/lib/WebSocketConnection.js:323:40

Basically i am trying to use the Types that i define in the runtime pallet. The types are auto-generated from the metadata using the @polkadot/typegen package.

Full code for reproducing this is here https://github.com/woss/substrate-mvce

2
Can you please include a valid payload for the Rule type - Shawn Tabrizi

2 Answers

1
votes

There is something wrong with the payload you are creating in TypeScript and sending to your Substrate node. The Substrate node does not seem to be able to parse the object.

I have found that you are definitely missing a property on the Operation type definition:

  Operation: {
    op: 'Vec<u8>',
    desc: 'Vec<u8>',
    hashAlgo: 'Vec<u8>',
    encodeAlgo: 'Vec<u8>',
    prefix: 'Vec<u8>',
    ops: 'Vec<Operation>',
  },

This is missing hashBits.

And looking further, it is not obvious that your pre-defined photo rules correctly satisfy the object definition defined by your runtime.

You need to check end to end that you have correctly defined these custom types and that the payload you are generating is valid.

1
votes

Yes, there was the hashBits missing but that wasn't the solution. After adding the hashBits AND made modifications to the definition to have EXACTLY the same structure ( same position of the keys) as in the runtime, then it worked as it should. This means following

pub struct Rule {
  version: u32,
  description: Vec<u8>,
  creator: Vec<u8>,
  for_what: ForWhat,
  parent: Vec<u8>,
  ops: Vec<Operation>,
  build_params: Operation,
}

Must be this in the JS app

{
  Rule: {
    version: 'u32',
    description: 'Vec<u8>',
    creator: 'Vec<u8>',
    forWhat: 'ForWhat',
    parent: 'Vec<u8>',
    ops: 'Vec<Operation>',
    buildParams: 'Operation',
  }
}

If we would change the order of the keys in the definition it will fail.