I was making a new way to add sovereign accounts for a particular Network ID. Like in this https://github.com/paritytech/polkadot/blob/HEAD/xcm/xcm-builder/src/location_conversion.rs

pub struct ChildParachainConvertsVia<ParaId, AccountId>(PhantomData<(ParaId, AccountId)>);
impl<ParaId: From<u32> + Into<u32> + AccountIdConversion<AccountId>, AccountId: Clone>
    Convert<MultiLocation, AccountId> for ChildParachainConvertsVia<ParaId, AccountId>
    fn convert_ref(location: impl Borrow<MultiLocation>) -> Result<AccountId, ()> {
        match location.borrow() {
            MultiLocation { parents: 0, interior: X1(Parachain(id)) } =>
            _ => Err(()),

    fn reverse_ref(who: impl Borrow<AccountId>) -> Result<MultiLocation, ()> {
        if let Some(id) = ParaId::try_from_account(who.borrow()) {
        } else {

It is a way to add sovereign account of Parachain in the Relay chain. There are also other examples where we can add sibling sovereign account also. I was making a new way to add sovereign account of particular NetworkId.

pub struct NetworkIdConvertsVia<Network, AccountId>(PhantomData<(Network, AccountId)>);
impl<Network: Get<NetworkId>, AccountId: From<[u8; 32]> + Into<[u8; 32]> + Clone >
    Convert<MultiLocation, AccountId> for NetworkIdConvertsVia<Network, AccountId> where xcm::v3::NetworkId: From<AccountId>

    fn convert(location: MultiLocation) -> Result<AccountId, MultiLocation> {
         let id = match location {

           MultiLocation { parents: 0, interior: X1(GlobalConsensus(network)) }  => network,  
        _=>return Err(location)

    // fn reverse(who: AccountId) -> Result<MultiLocation, AccountId> {
    // //Ok(GlobalConsensus(NetworkId()).into())
    // )
    // }

But I'm getting error "the trait From<xcm::v3::NetworkId> is not implemented for AccountId">please check

1 Answer 1


This error message suggests that you are trying to use an AccountId as a NetworkId in a call to the Cross-Consensus Message (XCM) module in the Substrate blockchain framework.

The From trait is a standard Rust trait that is used to define conversions between types. In this case, the Fromxcm::v3::NetworkId trait is required to convert an AccountId into a NetworkId type, which is used to identify the target network of a cross-chain message in the XCM protocol.

To resolve this error, you need to ensure that the AccountId is properly converted to a NetworkId before it is used in the XCM call. You can do this using the TryFrom trait from the sp_std::convert module, which allows you to attempt to convert between types and handle errors if the conversion fails.

Here's an example of how you can use TryFrom to convert an AccountId to a NetworkId:

use sp_std::convert::TryFrom;

use xcm::v3::{NetworkId, AccountId32};

// Convert an AccountId to a NetworkId let account_id = AccountId32::new([0u8; 32]); // Replace with your AccountId let network_id = NetworkId::try_from(account_id.clone()).map_err(|_| "Invalid network ID")?;

// Use the NetworkId in an XCM call let message = xcm::v3::Xcm::WithdrawAsset(xcm::v3::WithdrawAsset { assets: vec![xcm::v3::MultiAsset::ConcreteFungible(xcm::v3::FungibleAsset { id: [1u8; 32].into(), amount: 100.into(), })], effects: xcm::v3::WithdrawAssetEffects::Transfer(xcm::v3::Transact { origin_type: xcm::v3::OriginKind::SovereignAccount, origin: account_id.into(), require_weight_at_most: 100_000_000, call: xcm::v3::Call::System(xcm::v3::SystemCall::Remark(vec![1, 2, 3])), }), dest: xcm::v3::MultiLocation::X1( xcm::v3::Junction::AccountId32 { network: network_id.clone(), id: [2u8; 32].into(), } .into(), ), signer: xcm::v3::Signer::Sovereign(account_id), strategy: xcm::v3::WithdrawStrategy::All, max_payment: 100_000_000_000_000, });

// Send the XCM message xcm::send_xcm(message.into()).map_err(|_| "Failed to send XCM message")?;

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.