4

I was trying to transfer nft from relay chain to parachain through transact instruction of Xcm. Here is snippet of code I am using

Xcm(vec![Transact {
                    origin_kind:OriginKind::Xcm,
                    require_weight_at_most: Weight::from_parts(1_000, 1_000),
                    call: pallet_nfts::Call::<T, I>::create {
                        admin,
                        config
                    }
                    .encode()
                    .into(),
                }]),            )
             {  
                Ok((hash, cost)) => 
                     Self::deposit_event(Event::NftSent( hash, cost)),
                    
                Err(e) => 
                 Self::deposit_event(Event::NFTSendingError(e, )),          
} 

Through this I was trying to call create function of pallet-nfts on parachainfrom relay chain, the code executed successfully and received event NFTSent on relay chain. The problem I faced on parachain is Failed to Decode .

Here is the function create of pallet-nfts

pub fn create(
            origin: OriginFor<T>,
            admin: AccountIdLookupOf<T>,
            config: CollectionConfigFor<T, I>,
        ) -> DispatchResult {
            let collection =
                NextCollectionId::<T, I>::get().unwrap_or(T::CollectionId::initial_value());
                frame_support::log::warn!("kuch bi ");
            let owner = T::CreateOrigin::ensure_origin(origin, &collection)?;
            frame_support::log::warn!("ye owner hai bhai {:?}",owner);
            let admin = T::Lookup::lookup(admin)?;

In this function we are passing three parameters, Origin, admin, config.My question here is how should I call this transact instruction so that it pass successfully it will be very helpful any one can guide me on this. Below is the code snippet of the transaction instruction that I am using.

call: pallet_nfts::Call::<T, I>::create {
                        admin,
                        config

1 Answer 1

1

Here you can see an example that works for me.

let create_collection = relay_chain::RuntimeCall::Uniques(pallet_uniques::Call::<
            relay_chain::Runtime,
        >::create {
            collection: 1u32,
            admin: parachain_sovereign_account_id(1),
});
let mint = relay_chain::RuntimeCall::Uniques(pallet_uniques::Call::<relay_chain::Runtime>::mint {
                collection: 1u32,
                item: 1u32,
                owner: ALICE,
});

let create_collection_weight_estimation = Weight::from_parts(1_000_000_000, 10_000);
let mint_nft_weight_estimation = Weight::from_parts(1_000_000_000, 10_000);
let message = Xcm(vec![
            WithdrawAsset((Here, fees).into()),
            BuyExecution { fees: (Here, fees).into(), weight_limit: WeightLimit::Unlimited },
            Transact {
                origin_kind: OriginKind::SovereignAccount,
                require_weight_at_most: create_collection_weight_estimation,
                call: create_collection.encode().into(),
            },
            Transact {
                origin_kind: OriginKind::SovereignAccount,
                require_weight_at_most: mint_nft_weight_estimation,
                call: mint.encode().into(),
            },
        ]);

In your case you can skip the create_collection, if is already exist in the relay chain

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.