2

I have a local relaychain setup with 2 parachains Parachain A and Parachain B . I will like to execute an XCM message from Parachain A to execute an extrinsic on Parachain B using the Transact instruction.How do I achieve this programmatically without using polkadot.js webapp. Do I need to add pallet-xcm as a dependency , then write code in Parachain A to create the instruction and then call send which is on pallet-xcm? Is there any sample code that does this or detailed instruction on this or programmatically executing xcm?

// UPDATE

When sending Transact XCM Instruction from parachain A, how do I specify (or how does the xcm-executor know) the pallet / pallet id on the target Parachain B which contains the extrinsic to be executed, or is it not required?

for example. The following Transact Xcm message is sent from parachain A to execute an extrinsic called ping defined in the cumulus-ping pallet on Parachain B. In the xcm message below, I do not see the cumulus-ping pallet or the index of the cumulus-ping pallet specified in the XCM instruction. so how does XCM determine the pallet / module where the ping extrinsic on Parachain B is located? The code I attached below is from the cumulus repo here

// This is Parachain A, which sends the xcm message

send_xcm::<T::XcmSender>(
                    (Parent, Junction::Parachain(para.into())).into(),
                    Xcm(vec![Transact {
                        origin_kind: OriginKind::Native,
                        require_weight_at_most: Weight::from_parts(1_000, 1_000),
                        call: <T as Config>::RuntimeCall::from(Call::<T>::ping {
                            seq,
                            payload: payload.clone().to_vec(),
                        })
                        .encode()
                        .into(),
                    }]),
                ) 

// This is the runtime of patachain B which contains cumulus-ping pallet which has the ping extrinsic

construct_runtime! {
    pub enum Runtime where
        Block = Block,
        NodeBlock = generic::Block<Header, sp_runtime::OpaqueExtrinsic>,
        UncheckedExtrinsic = UncheckedExtrinsic,
    {
        System: frame_system::{Pallet, Call, Storage, Config, Event<T>},
        ...
        Spambot: cumulus_ping::{Pallet, Call, Storage, Event<T>} = 99,
    }
}

1 Answer 1

1

There are no detailed instructions explaining how to use transact, but there is an demo article by OAK network that explains the working of XCMP and in that they have used cumulus_ping that is using transact instruction here. It helped me a lot in understanding the working of transact instruction I hope it helps you too.

3
  • When sending the Transact XCM Instruction from parachain A, how is the target pallet Id which contains the extrinsic to be executed specified? I have updated the question
    – Neo
    Commented Jul 20, 2023 at 20:04
  • I am also currently doing R&D on transact instruction , so I am also not sure how it identifies the pallet, for now what I understand is that we need to specify the transact instruction in the same pallet on which we want on other chain. Commented Jul 21, 2023 at 5:09
  • Do you mean that the pallets on both receiving (pallet which initiates the xcm) and destination (pallet which contains the extrinsic) chain should have same name ?
    – Neo
    Commented Jul 21, 2023 at 15:01

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.