0

I have custom RPC, which looks like so

#[rpc(client, server)]
pub trait SomeRpcApi {
    #[method(name = "some_submitData")]
    async fn submit_data(
        &self,
        id: u64,
        message: [u8; 32],
    ) -> RpcResult<()>;
}

and I'm trying to call it using this TS script

const api = await ApiPromise.create({
    provider: wsProvider,
    rpc: {
        some: {
            submitData: {
                description: '',
                params: [
                    {
                        name: 'id',
                        type: 'u64'
                    },
                    {
                        name: 'message',
                        type: '[u8; 32]'
                    }
                ],
                type: 'RpcResult<((), u32)>'
            }
        }
    }
});
const message = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32]);
const id = api.createType('u64', 1);
const data = api.createType('[u8; 32]', message);
const resp = await api.rpc.time.submitForSigning(id, data);

bun on submitting I'm getting this error:

RPC-CORE: submitData(id: u64, message: [u8; 32]): RpcResult<((), u32)>:: -32602: invalid type: string "0x1ddf7f02f19991b8e2b56d7e325f05835bb1d66b5c0d87ba98b4230f2a28c085", expected a sequence at line 1 column 68

Where's the issue here? Thanks.

5
  • Dont know if that is what is causing the issue; but the return type looks different. Feb 1, 2023 at 17:14
  • changing it makes no difference to error - used this one from one of similar questions as this seem to work for other folks. Feb 1, 2023 at 18:12
  • tried changing it to Vec<u8> and getting this error on it's construction: Error: createType(Vec<u8>):: Bytes: required length less than remainder, expected at least 14281, found 32 Feb 2, 2023 at 9:30
  • 1
    Could you please share the code? Its always difficult to debug such things remotely. Feb 2, 2023 at 10:16
  • Can't share code. From latest findings - if sending u16...u64 it works. if sending u8 - it considers as a string. polkadot-v0.9.30 if that helps. Vec<u8> works with 10 bytes at most, and then error... Feb 7, 2023 at 8:01

2 Answers 2

1

[u8; 32] is basically an array of u8. Try directly with the array you have:

    const message = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32];
  
    const id = api.createType('u64', 1);
    
    const resp = await api.rpc.time.submitForSigning(id, message);
6
  • tried everything, including Array.from(U8Array) to make sure it's array. I assume problem might be somewhere at Codec::encode() -> RPC method, which does not Vec<u8>::decode(). Feb 27, 2023 at 9:02
  • It worked for me like this, without Polkakdot JS where you able to request the RPC some_submitData succesfully?
    – Alex Bean
    Feb 27, 2023 at 11:23
  • apparently there's some compactFromU8aLim function called before sending, which produces my error. Mar 1, 2023 at 8:33
  • Then it needs the Uint8Array type as an input: github.com/polkadot-js/common/blob/master/packages/util/src/…
    – Alex Bean
    Mar 1, 2023 at 9:32
  • How you discover this is the method that throws the error?
    – Alex Bean
    Mar 1, 2023 at 9:32
0

you need to pass message as an array[u8; 32] not as a hex string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.