0

I'm trying to create the encoded element for an XCM V0 transact call such as:

const message = {
    V0: {
        Transact: {
            originType: "Native",
            requireWeightAtMost: 100000,
            call: {
                encoded: "0x280016000000" //ex: templatePallet.doSomething(22)
            }
        }
    }
}

But how to create the encoded call ?

I've tried this without success:

let templatePallet_hex_call = await parachainApiInstInsurance.tx.templatePallet.doSomething(22).signAsync(account);
...
const message = {
    V0: {
        Transact: {
            originType: "Native",
            requireWeightAtMost: 100000,
            call: {
                encoded: compactAddLength(hexToU8a(templatePallet_hex_call.toHex()))
            }
        }
    }
}

Any clue or documentation for this ? Thanks in advance.

PS: I've seen this thread but it's not using javascript.

1 Answer 1

3

When you construct via api.tx.* is creates an unsigned extrinsic. So basically you want the call-only part of that.

// output as hex
const encoded = u8aToHex(
  // add length to the U8a (double-encoding)
  compactAddLength(
    // convert the method-only part to Uint8Array
    templatePallet_hex_call
      .method
      .toU8a()
  )
);

This part is not signed, so you can forgo the signAsync in your code. The requirement here is for the length + call indexes + call data. The signing is only for extrinsics, not call data.

1
  • 2
    Thats why I had an additional byte ! So the call seems to be ok (no FailedToDecode error), but now a BadOrigin appeared... Anyhow you solved the thread question thanks !
    – lucgerrits
    Jul 12, 2022 at 18:32

Your Answer

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

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